java程序菜鸟问题
来源:百度知道 编辑:UC知道 时间:2024/05/11 03:31:50
import java.awt.event.*;
class button{
JFrame c =new JFrame("Welcome!");
JButton a=new JButton("hello!");
JCheckBox b=new JCheckBox("hi!");
JLabel f=new JLabel("chose a button plz!");
public button(){
a.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){f.setText("you chose a normal button!");
}
});
c.getContentPane().add(f);
c.getContentPane().add(a);
c.getContentPane().add(b);
c.getContentPane().setLayout(new java.awt.FlowLayout());
c.setSize(200,250);
c.setVisible(true);
c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
button d=new button();
}
}
--------------------
其中a.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){f.set
开头应该这样写:
class button implements ActionListener{
/*more code*/
}
import javax.swing.*;
import java.awt.event.*;
class button{
JFrame c =new JFrame("Welcome!");
JButton a=new JButton("hello!");
JCheckBox b=new JCheckBox("hi!");
JLabel f=new JLabel("chose a button plz!");
public button()
{
a.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
f.setText("you chose a normal button!");
}
});
c.getContentPane().add(f);
c.getContentPane().add(a);
c.getContentPane().add(b);
c.getContentPane().setLayout(new java.awt.FlowLayout());
c.setSize(200,250);
c.se