import java.applet.*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MyWindow extends JFrame implements ActionListener{
private JButton button1,button2;
private static int flg=0;
private static JTextField text1,text2;
Mywindow(String s){
super(s);
Container con = this.getContentPane();
con.setLayout(new GridLayout(2,2));
this.setSize(200,100);
this setLocation(100,100);
button1 = new JButton("选择水果");
button2 = new JButton("选择食品");
button1.addActionListener(this);
button2.addActionListener(this);
text1 = new JTextField(20);
text2 = new JTextField(20);
con.add(button1);
con.add(button2);
con.add(text1);
con.add(text2);
this.setVisible(true);
this.pack();
}
public static void returnName(String s){
if(flg ==1)
text1.setText("选择的水果是:"+s);
else if(flg == 2)
text2.setText("选择的食品是:"+s);
}
public void actionPerformed(ActionEvent e){
MyDialog dialog;
if(e.getSource()==button1){
dialog = new MyDialog(this,"水果");
dialog.setVisible(true);
flg =1;
}
else if(e.getSource()==button2){
dialog =new MyDialog(this,"食品");
dialog.setVisible(true);
flg=2;
}
}
}
class MyDialog extends JDialog implements ActionListener{
JLabel title;
JTextField text;
JButton done;
Mydialog(JFrame F,String s){
super(F,s,true);//模态
Container con = this.getContentPane();
title = new JLabel("输入"+s+"名称");
text = new JTextField(10);
text.setEditable(true);
con.setLayout(new FlowLayout());
con.setSize(200,100);
setModal(false);
done = new JButton("确定");
done.addActionListener(this);
con.setVisible(true);
this.pack();
}
public void actionPerformed(ActionEvent e){
MyWindow.returnName(text.getText());
setVisible(false);
dispose();
}
}
public class Example6_6 extends Applet{
MyWindow window;
MyDialog dialog;
public void init(){
window = new MyWindow("带对话框窗口");
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==text){
MyWindow.returnName(text.getText());
}
else if(e.getSource()==done){
MyWindow.returnName(text.getText());
setVisible(false);
dispose();//清除资源
}
}
int result = JOptionPane.showConfirmDialog(parent,“确实要退出吗”, “退出确认“,JOptionPane.YES_NO_CANCEL_OPTION);
String result = (String)JOptionPane.showInputDialog(parent,
“请选择一项运动项目”, “这是运动项目选择对话框”,
JOptionPane.QUESTION_MESSAGE,null,
new Object[]{“踢足球“,“打篮球”,“跑步”,“跳绳”},“跑步”);
JOptionPane.showMessageDialog(parent, “这是一个Java程序”,
“我是输出信息对话框”,JOptionPane.PLAIN_MESSAGE);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有