各位大虾 为什么我的按扭没有用啊
只有else 有用 真是搞不懂 求大家帮我调试一下,告诉我那里去错了
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class tfhlayout extends JFrame implements ActionListener{
public JButton button1,button2,button3,button4;
JTextArea area=new JTextArea(14,28);
public void tfhlayout(){
JFrame frame;
JPanel p1,p2;
p1=new JPanel();
p2=new JPanel();
frame= new JFrame("tfh 的文档");
p1.setLayout(new BoxLayout(p1,BoxLayout.Y_AXIS));
Container con=frame.getContentPane();
con.setLayout(new BorderLayout(1,1));
JButton button1=new JButton("谭福会说");
JButton button2=new JButton("龙敏杰说");
JButton button3=new JButton("吴明细说");
JButton button4=new JButton("谭文娟说");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
p1.add(button1);
p1.add(button2);
p1.add(button3);
p1.add(button4);
con.add("West",p1);
p2.add(area);
con.add(p2);
frame.setSize(400,300);
frame.show();
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button4)
{ JOptionPane.showMessageDialog(null,"Hello","Hello",JOptionPane.INFORMATION_MESSAGE);
area.setText("button1");
}
else if(e.getSource()==button2)
area.setText("button2");
else if (e.getSource()==button3)
area.setText("button3");
else if(e.getSource()==button4)
{ JOptionPane.showMessageDialog(null,"Button4","Hello",JOptionPane.INFORMATION_MESSAGE);
area.setText("button4");}
else area.setText("null");
}
public static void main(String[] args){
tfhlayout app = new tfhlayout();
app.tfhlayout();
}
}
只有else 有用 真是搞不懂 求大家帮我调试一下,告诉我那里去错了
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class tfhlayout extends JFrame implements ActionListener{
public JButton button1,button2,button3,button4;
JTextArea area=new JTextArea(14,28);
public void tfhlayout(){
JFrame frame;
JPanel p1,p2;
p1=new JPanel();
p2=new JPanel();
frame= new JFrame("tfh 的文档");
p1.setLayout(new BoxLayout(p1,BoxLayout.Y_AXIS));
Container con=frame.getContentPane();
con.setLayout(new BorderLayout(1,1));
JButton button1=new JButton("谭福会说");
JButton button2=new JButton("龙敏杰说");
JButton button3=new JButton("吴明细说");
JButton button4=new JButton("谭文娟说");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
p1.add(button1);
p1.add(button2);
p1.add(button3);
p1.add(button4);
con.add("West",p1);
p2.add(area);
con.add(p2);
frame.setSize(400,300);
frame.show();
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button4)
{ JOptionPane.showMessageDialog(null,"Hello","Hello",JOptionPane.INFORMATION_MESSAGE);
area.setText("button1");
}
else if(e.getSource()==button2)
area.setText("button2");
else if (e.getSource()==button3)
area.setText("button3");
else if(e.getSource()==button4)
{ JOptionPane.showMessageDialog(null,"Button4","Hello",JOptionPane.INFORMATION_MESSAGE);
area.setText("button4");}
else area.setText("null");
}
public static void main(String[] args){
tfhlayout app = new tfhlayout();
app.tfhlayout();
}
}