?? jdialogframe1.java~44~
字號:
package dialogexample;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public class JDialogFrame1 extends JFrame {
JPanel contentPane;
FlowLayout flowLayout1 = new FlowLayout();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
ImageIcon a1=new ImageIcon(".\\b1.jpg");
JButton jButton5 = new JButton();
JLabel jLabel1 = new JLabel();
JPanel jPanel3 = new JPanel();
JButton jButton6 = new JButton();
JButton jButton7 = new JButton();
public JDialogFrame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(flowLayout1);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jButton1.setText("show");
jButton1.addActionListener(new JDialogFrame1_jButton1_actionAdapter(this));
jButton2.setText("jButton2");
jButton2.addActionListener(new JDialogFrame1_jButton2_actionAdapter(this));
jPanel1.setBackground(Color.red);
jPanel2.setBackground(Color.pink);
jButton3.setText("confirm dialog");
jButton3.addActionListener(new JDialogFrame1_jButton3_actionAdapter(this));
jButton4.setText("show error icon");
jButton4.addActionListener(new JDialogFrame1_jButton4_actionAdapter(this));
jButton5.setText("Input dialog");
jButton5.addActionListener(new JDialogFrame1_jButton5_actionAdapter(this));
jLabel1.setText("您輸入:");
jButton6.setText("自定義按鈕");
jButton6.addActionListener(new JDialogFrame1_jButton6_actionAdapter(this));
jPanel3.setBackground(Color.orange);
jButton7.setText("jButton7");
contentPane.add(jPanel3);
jPanel3.add(jButton6);
contentPane.add(jPanel2);
jPanel2.add(jButton5);
jPanel2.add(jButton4);
jPanel2.add(jButton3);
contentPane.add(jPanel1);
contentPane.add(jLabel1);
jPanel1.add(jButton1);
jPanel1.add(jButton2);
jPanel3.add(jButton7);
jPanel3.getRootPane().setDefaultButton(jButton7);
}
public void jButton1_actionPerformed(ActionEvent e) {
// Dialog1 d1=new Dialog1();
// d1.setSize(200,110);
// d1.setVisible(true);
Dialog2 d2=new Dialog2();
d2.setSize(200,150);
d2.setVisible(true);
}
public void jButton2_actionPerformed(ActionEvent e) {
}
public void jButton4_actionPerformed(ActionEvent e) {
//只有一個確定按鈕
// JOptionPane.showMessageDialog(this,"錯誤調試","錯誤",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this,"錯誤調試","錯誤",JOptionPane.INFORMATION_MESSAGE,a1);
}
public void jButton3_actionPerformed(ActionEvent e) {
// JOptionPane.showConfirmDialog(this,"comfirm dialog","提示信息",JOptionPane.YES_NO_OPTION,JOptionPane.DEFAULT_OPTION,a1);
JOptionPane.showConfirmDialog(this,"comfirm dialog","提示信息",JOptionPane.OK_CANCEL_OPTION,JOptionPane.ERROR_MESSAGE);
}
public void jButton5_actionPerformed(ActionEvent e) {
//JOptionPane.showInputDialog(this,"請輸入","輸入窗口",JOptionPane.QUESTION_MESSAGE);
//下拉列表
String [] values={"aaa","abc","dsfds"};
String result="";
// result=(String)JOptionPane.showInputDialog(this,"請輸入","輸入窗口",JOptionPane.QUESTION_MESSAGE,null,values,values[0]);
result=(String)JOptionPane.showInputDialog(this,"請輸入姓名","提示",JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showInputDialog(this,"請輸入","提示",JOptionPane.INFORMATION_MESSAGE,null,values,values[1]);
jLabel1.setText(" 你輸入的姓名是:"+result);
}
public void jButton6_actionPerformed(ActionEvent e) {
String [] option={"脫產22","脫產24"};
JOptionPane.showOptionDialog(this,"請選擇","提示",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE,a1,option,option[1]);
// String [] option={"喜歡","不喜歡","取消"};
// int result=JOptionPane.showOptionDialog(this,"你喜歡java嗎!","題目",
// JOptionPane.YES_NO_CANCEL_OPTION,
// JOptionPane.QUESTION_MESSAGE,null,option,option[1]);
// if(result==JOptionPane.YES_OPTION)
// {
// jLabel1.setText(result+" 喜歡");
// }
// if(result==JOptionPane.NO_OPTION)
// {
// jLabel1.setText(result+"不喜歡");
// }
// if(result==JOptionPane.CANCEL_OPTION)
// {
// jLabel1.setText(result+"取消");
// }
// if(result==JOptionPane.CLOSED_OPTION)
// {
// jLabel1.setText(result+"關閉");
// }
}
}
class JDialogFrame1_jButton6_actionAdapter implements ActionListener {
private JDialogFrame1 adaptee;
JDialogFrame1_jButton6_actionAdapter(JDialogFrame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton6_actionPerformed(e);
}
}
class JDialogFrame1_jButton5_actionAdapter implements ActionListener {
private JDialogFrame1 adaptee;
JDialogFrame1_jButton5_actionAdapter(JDialogFrame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}
class JDialogFrame1_jButton3_actionAdapter implements ActionListener {
private JDialogFrame1 adaptee;
JDialogFrame1_jButton3_actionAdapter(JDialogFrame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class JDialogFrame1_jButton4_actionAdapter implements ActionListener {
private JDialogFrame1 adaptee;
JDialogFrame1_jButton4_actionAdapter(JDialogFrame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class JDialogFrame1_jButton2_actionAdapter implements ActionListener {
private JDialogFrame1 adaptee;
JDialogFrame1_jButton2_actionAdapter(JDialogFrame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class JDialogFrame1_jButton1_actionAdapter implements ActionListener {
private JDialogFrame1 adaptee;
JDialogFrame1_jButton1_actionAdapter(JDialogFrame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -