📄 message.java
字号:
package yu3;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Message extends JFrame implements ActionListener{
private JButton b1,b2,b3,b4;
public Message(){
super();
JOptionPane.showMessageDialog(null, "你好!欢迎进入");
this.setDefaultCloseOperation(3);
b1=new JButton("Message");
b1.addActionListener(this);
b2=new JButton("confirm");
b2.addActionListener(this);
b3=new JButton("input");
b3.addActionListener(this);
b4=new JButton("other");
b4.addActionListener(this);
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(b1);
this.getContentPane().add(b2);
this.getContentPane().add(b3);
this.getContentPane().add(b4);
this.setBounds(400,400, 600, 600);
this.setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Message"))
{JOptionPane.showMessageDialog(null, "hello....");
}
if(e.getSource()==b2)
/*{ int st=JOptionPane.showConfirmDialog(null, "Are you sure");
}*/
{ JComboBox cb=new JComboBox();
cb.addItem("1");
cb.addItem("2");
cb.addItem("3");
cb.addItem("4");
cb.addItem("5");
JTextField[] tf=new JTextField[8];
for(int i=0;i<tf.length;i++){
tf[i]=new JTextField(10);
if(i%2==0){ tf[i].setEnabled(false);
}
}
tf[0].setText("input you name");
tf[2].setText("input you sex");
tf[4].setText("input you age");
tf[6].setText("input you address");
int st=JOptionPane.showConfirmDialog(null, tf);
if(st==JOptionPane.YES_OPTION){
System.out.println("name"+" "+tf[1].getText());
System.out.println("sex"+" "+tf[3].getText());
System.out.println("age"+" "+tf[5].getText());
System.out.println("address"+" "+tf[7].getText());
}}
if(e.getSource()==b3)
{ String name=JOptionPane.showInputDialog("请输入你的名字");
System.out.println(name);
}
if(e.getSource()==b4)
{JOptionPane.showMessageDialog(null, ERROR, "警告", JOptionPane.WARNING_MESSAGE);
}
}
public static void main(String args[])
{ new Message();}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -