为什么我的按扭只有一个else语句的有用啊

各位大虾 为什么我的按扭没有用啊
只有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();

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值