⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdialogframe1.java~42~

📁 JAVA教学用代码
💻 JAVA~42~
字号:
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);
        this.getRootPane().setDefaultButton(jButton2);
    }

    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 + -