该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package javaSwing;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
class exx3_1 extends JFrame implements ActionListener{
Box v1;
JTextField input1, input2, input3;
ActionListener listener;
public exx3_1() {
// TODO Auto-generated constructor stub
setBounds(600,150,300,400);//默认本容器对象的
init();
input3.setEditable(false);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init() {
setTitle("三条腿的青蛙");//默认是此Jframe 底层容器
input1 = new JTextField();
input2 = new JTextField();
input3 = new JTextField();
v1=Box.createVerticalBox();
v1.add(new JLabel("哈哈 算数开始啦"));
v1.add(Box.createVerticalStrut(50));
v1.add(input1);
v1.add(Box.createVerticalStrut(50));
v1.add(input2);
v1.add(Box.createVerticalStrut(50));
v1.add(input3);
v1.add(new JLabel("翻滚吧 牛宝宝"));//为啥jlabel不回收啊 明明是临时创建的啊
add(v1);
input3.addActionListener(listener);//加上监听器
input1.addActionListener(listener);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
if(e.getSource()==input1){
int h=Integer.parseInt(input1.getText());
if (100<=h||h<=200){
}
else {
JOptionPane.showMessageDialog(v1,"请输入100-200之内的数字","消息对话框",JOptionPane.WARNING_MESSAGE);
}
}
else if(e.getSource()==input3){
input3.setText(String.valueOf(Integer.parseInt(input1.getText())+Integer.parseInt(input2.getText())));
}
}
}
public class EX3_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
exx3_1 hehe;
hehe = new exx3_1();
}
}