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

📄 dialog.java

📁 java技术内幕源代码,配合书籍看有事半功倍的效果
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/*
<APPLET
    CODE = dialog.class
    WIDTH = 350
    HEIGHT = 280>
</APPLET>
*/

public class dialog extends JApplet implements ActionListener
{
    JLabel jlabel = new JLabel("Click the OK or Cancel button");

    JButton jbutton1 = new JButton("Display dialog"),
        jbutton2 = new JButton("OK"),
        jbutton3 = new JButton("Cancel");

    private JDialog dialog = new JDialog((Frame) null, 
        "Dialog", true);

    public void init() 
    {
        Container contentPane = getContentPane();
        Container dialogContentPane = dialog.getContentPane();

        contentPane.setLayout(new FlowLayout());
        contentPane.add(jbutton1);

        dialogContentPane.setLayout(new FlowLayout());

        dialogContentPane.add(jlabel);
        dialogContentPane.add(jbutton2);
        dialogContentPane.add(jbutton3);

        jbutton1.addActionListener(this);
        jbutton2.addActionListener(this);
        jbutton3.addActionListener(this);
    }
    
    public void actionPerformed(ActionEvent e) 
    {
        if(e.getSource() == jbutton1) {
            dialog.setBounds(200, 200, 200, 120);
            dialog.show();
        } else if(e.getSource() == jbutton2) {
            showStatus("You clicked OK");
            dialog.dispose();
        } else if(e.getSource() == jbutton3) {
            showStatus("You clicked Cancel");
            dialog.dispose();
        }
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -