一个JAVA程序改错问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 18:16:54
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Ex9_5{
public static void main(String[] agrs){
JFrame f=new JFrame("Simple Swing Application");
Container contentPane=f.getcontentPane();
contentPane.setLayout(new GridLayout(2,1));
JButton button=new JButton("Click me");
final JLabel label=new JLabel();
contentPane.add(button);
contentPane.aa(label);
button.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
String information=JOptionPane.showInputDialog("请输入");
label.setText(information);
}
}
);
f.setsize(200,100);
f.show();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
编译出错信息是这样的
---------- 编译 ----------
Ex9_5.java:7: cannot find symbol
symbol : method getcontentPane()
location: class javax.swing.JFrame

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Ex9_5 {
public static void main(String[] agrs) {
JFrame f = new JFrame("Simple Swing Application");
Container contentPane = f.getContentPane();
contentPane.setLayout(new GridLayout(2, 1));
JButton button = new JButton("Click me");
final JLabel label = new JLabel();
contentPane.add(button);
contentPane.add(label);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
String information = JOptionPane.showInputDialog("请输入");
label.setText(information);
}
});
f.setSize(200, 100);
f.setVisible(true);