GUI

GUI编程

组件(component)

  • 窗口
  • 弹窗
  • 面板
  • 文本框(textarea)
  • 列表框
  • 按钮(button)
  • 图片
  • 监听事件
  • 鼠标
  • 键盘

1、简介

GUI的核心技术:Swing AWT

  • 界面不够美观
  • 需要jre环境
    为什么要学习?
  • 可以写出自己想要的一些小工具
  • 工作时候,也可能需要维护到swing界面,概率极小
  • 了解MVC架构,了解监听

2、AWT

介绍

1、包含了很多类和接口!GUI:图形用户界面。
2、元素:窗口、按钮、文本框
3、java.awt
4、enter description here

组件和容器

1、Frame(窗体)

public static void main(String[] args) {
        //Frame
        Frame frame = new Frame("图形界面窗口");//创建在内存中
        //需要设置可见性
        frame.setVisible(true);
        //设置窗口大小
        frame.setSize(400,400);
        //设置背景颜色
        frame.setBackground(new Color(0, 250, 242));
        //弹出的初始位置
        frame.setLocation(200,200);
        //设置大小固定
        frame.setResizable(false);
    }

结果图
enter description here
问题:发现窗口关闭不掉,停止java程序
尝试回顾封装

 public static void main(String[] args) {
        //展示多个窗口  (new多个对象)
        myframe myframe1 = new myframe(100, 100, 200, 200, Color.BLUE);
        myframe myframe2 = new myframe(300, 100, 200, 200, Color.yellow);
        myframe myframe3 = new myframe(100, 300, 200, 200, Color.red);
        myframe myframe4 = new myframe(300, 300, 200, 200, Color.green);
    }
}
class myframe extends Frame {
    static int id=0;
    public myframe(int x,int y,int w,int h,Color c){
        super("myframe"+(++id));
        setBounds(x,y,w,h);
        setBackground(c);
        setVisible(true);
    }

结果图
enter description here

2、Panel(面板)

public static void main(String[] args) {
        Frame frame = new Frame();
        //布局的概念
        Panel panel = new Panel();
        //设置布局
        frame.setLayout(null);
        //坐标
        frame.setBounds(300,300,500,500);
        frame.setBackground(new Color(6, 132, 63));
        //panel的坐标,相对frame的坐标
        panel.setBounds(50,50,400,400);
        panel.setBackground(new Color(13, 120, 168));
        frame.add(panel);
        frame.setVisible(true);
        //监听事件,监听关闭事件  System.exit(0)
        frame.addWindowListener(new WindowAdapter() {
            //窗口点击关闭时需要完成的事情
            @Override
            public void windowClosing(WindowEvent e) {
                //结束程序
                System.exit(0);
            }
        });
    }

enter description here

3、布局管理器

  • 流式布局(FlowLayout)
//流式布局(从左到右)
    public static void main(String[] args) {

        Frame frame = new Frame();
        frame.setSize(400,400);

        Button button1 = new Button("button1");
        Button button2 = new Button("button2");
        Button button3 = new Button("button3");

        frame.setVisible(true);
        //frame.setLayout(new FlowLayout());//居中
        //frame.setLayout(new FlowLayout(FlowLayout.LEFT));//靠左
        frame.setLayout(new FlowLayout(FlowLayout.RIGHT));//靠右
        frame.add(button1);
        frame.add(button2);
        frame.add(button3);
    }

enter description here

  • 东西南北中(BorderLayout)
//东西南北中
    public static void main(String[] args) {
        Frame frame = new Frame();
        Button east = new Button("East");
        Button west = new Button("West");
        Button south = new Button("South");
        Button north = new Button("North");
        Button center = new Button("Center");
        frame.setVisible(true);
        frame.add(east,BorderLayout.EAST);
        frame.add(west,BorderLayout.WEST);
        frame.add(south,BorderLayout.SOUTH);
        frame.add(north,BorderLayout.NORTH);
        frame.add(center,BorderLayout.CENTER);
        frame.setSize(400,400);
    }

enter description here

  • 表格布局(GridLayout)
public static void main(String[] args) {
        Frame frame = new Frame();
        frame.setVisible(true);
        Button button1 = new Button("1");
        Button button2 = new Button("2");
        Button button3 = new Button("3");
        Button button4 = new Button("4");
        Button button5 = new Button("5");
        Button button6 = new Button("6");
        frame.setLayout(new GridLayout(3,2));
        frame.add(button1);
        frame.add(button2);
        frame.add(button3);
        frame.add(button4);
        frame.add(button5);
        frame.add(button6);
        frame.pack();//Java函数  自动填充
    }

enter description here

小练习
public static void main(String[] args) {
        Frame frame = new Frame();
        frame.setLayout(new GridLayout(2,1));
        frame.setSize(400,300);
        frame.setLocation(100,100);

        Panel panel1 = new Panel(new BorderLayout());
        Panel panel2 = new Panel(new GridLayout(2,1));
        Panel panel3 = new Panel(new BorderLayout());
        Panel panel4 = new Panel(new GridLayout(2,2));
        frame.setVisible(true);
        Button button1 = new Button();
        Button button2 = new Button();
        Button button3 = new Button();
        Button button4 = new Button();
        Button button5 = new Button();
        Button button6 = new Button();
        Button button7 = new Button();
        Button button8 = new Button();
        Button button9 = new Button();
        Button button10 = new Button();

        panel1.add(button1,BorderLayout.WEST);
        panel1.add(button2,BorderLayout.EAST);
        panel1.add(panel2,BorderLayout.CENTER);
        panel2.add(button3);
        panel2.add(button4);


        panel3.add(button5,BorderLayout.WEST);
        panel3.add(button6,BorderLayout.EAST);
        panel3.add(panel4,BorderLayout.CENTER);
        panel4.add(button7);
        panel4.add(button8);
        panel4.add(button9);
        panel4.add(button10);


        frame.add(panel1);
        frame.add(panel3);
		}

enter description here

4、事件监听

多个按钮可以共享一个监听事件

public static void main(String[] args) {
        //两个按钮实现同一个事件
        //开始   停止
        Frame frame = new Frame("开始-停止");
        Button button1 = new Button("start");
        Button button2 = new Button("stop");
        frame.add(button1,BorderLayout.NORTH);
        frame.add(button2,BorderLayout.SOUTH);
        frame.setVisible(true);
        frame.pack();
        WindowsClosing(frame);
        //可以显示的定义触发会返回的命令。如果不显示定义,则会走默认的值。
        //可以多个按钮只写一个监听器
        button2.setActionCommand("button2-stop");
        MyMonitor myMonitor = new MyMonitor();
        button1.addActionListener(myMonitor);
        button2.addActionListener(myMonitor);
    }
    //关闭事件
    private static void WindowsClosing(Frame frame){
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}
class MyMonitor implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("发生的事件"+e.getActionCommand());
    }

enter description here

5、输入框(TextField)监听事件

一般情况下main方法只用来启动
设置替换编码是 setEchoChar
textField.setText(""); 可以让事件发生后文本框变为空

public class TestText01 {
    public static void main(String[] args) {
        //一般情况下main方法只管启动
        new MyFrame();
    }
}
class MyFrame extends Frame{
    public MyFrame(){
        TextField textField = new TextField();
        add(textField);
        setVisible(true);
        pack();
        //监听文字框输入的文字
        MyActionListener2 myActionListener2 = new MyActionListener2();
        //按下回车,就会触发这个事件
      
	  textField.addActionListener(myActionListener2);
        //设置替换编码
        textField.setEchoChar('*');
    }
}
class MyActionListener2 implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
        TextField textField = (TextField) e.getSource();//获得文本框的资源,返回一个对象
        System.out.println(textField.getText());//获得输入框的文本
        textField.setText("");//null
    }
}

enter description here

6、简易计算器,组合+内部类回顾复习

oop:组合,大于继承

目前代码

public class TestCalculator {
    public static void main(String[] args) {
new Calculator();
    }
}
class Calculator extends Frame{
    public Calculator(){
        //三个文本框
        TextField textField1 = new TextField(10);
        TextField textField2 = new TextField(10);
        TextField textField3 = new TextField(12);
        //一个标签
        Label label = new Label("+");
        //一个按钮
        Button button = new Button("=");
		//按钮事件
        button.addActionListener(new mymonistor(textField1,textField2,textField3));
        //布局
        setLayout(new FlowLayout());
        add(textField1);
        add(label);
        add(textField2);
        add(button);
        add(textField3);
        pack();
        setVisible(true);
    }
}
//监听事件
class mymonistor implements ActionListener{
    private TextField textField1,textField2,textField3;
    public mymonistor(TextField textField1,TextField textField2,TextField textField3){
        this.textField1=textField1;
        this.textField2=textField2;
        this.textField3=textField3;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        //11获得加数和被加数
        int n1 = Integer.parseInt(textField1.getText());
        int n2 = Integer.parseInt(textField2.getText());
        //结果放入第三个框
        textField3.setText(""+(n1+n2));
        //前两个框清空
        textField1.setText("");
        textField2.setText("");
    }
}

完全改造为面向对象
用对象进行属性的引用

public class TestCalculator {
    public static void main(String[] args) {
        new Calculator().LoadFrame();
    }
}
class Calculator extends Frame{
    TextField textField1,textField2,textField3;
    public void LoadFrame(){
        //三个文本框
        textField1 = new TextField(10);
        textField2 = new TextField(10);
        textField3 = new TextField(12);
        //一个标签
        Label label = new Label("+");
        //一个按钮
        Button button = new Button("=");
        button.addActionListener(new mymonistor(this));
        //布局
        setLayout(new FlowLayout());
        add(textField1);
        add(label);
        add(textField2);
        add(button);
        add(textField3);
        pack();
        setVisible(true);
    }
}
class mymonistor implements ActionListener{
    Calculator calculator=null;
    public mymonistor(Calculator calculator){
        this.calculator=calculator;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        //11获得加数和被加数
        int n1 = Integer.parseInt(calculator.textField1.getText());
        int n2 = Integer.parseInt(calculator.textField2.getText());
        //结果放入第三个框
        calculator.textField3.setText(""+(n1+n2));
        //前两个框清空
        calculator.textField1.setText("");
        calculator.textField2.setText("");
    }
}

内部类:

  • 更好的包装
    内部类最大的好处就是可以畅通无阻的访问外部类。
public class TestCalculator {
    public static void main(String[] args) {
        new Calculator().LoadFrame();
    }
}
class Calculator extends Frame{
    TextField textField1,textField2,textField3;
    public void LoadFrame(){
        //三个文本框
        textField1 = new TextField(10);
        textField2 = new TextField(10);
        textField3 = new TextField(12);
        //一个标签
        Label label = new Label("+");
        //一个按钮
        Button button = new Button("=");
        button.addActionListener(new mymonistor());
        //布局
        setLayout(new FlowLayout());
        add(textField1);
        add(label);
        add(textField2);
        add(button);
        add(textField3);
        pack();
        setVisible(true);
    }
    private class mymonistor implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            //11获得加数和被加数
            int n1 = Integer.parseInt(textField1.getText());
            int n2 = Integer.parseInt(textField2.getText());
            //结果放入第三个框
            textField3.setText("" + (n1 + n2));
            //前两个框清空
            textField1.setText("");
            textField2.setText("");
        }
    }
}

7、画笔

public class TestPaint {
    public static void main(String[] args) {
new MyPaint().LoadFrame();
    }
}
class MyPaint extends Frame{
    public void LoadFrame(){
        setBounds(100,100,600,500);
        setVisible(true);
    }
    @Override
    public void paint(Graphics g) {
        g.setColor(new Color(31, 111, 132));
        g.drawOval(100,100,200,200);//空心圆
        g.fillOval(100,100,200,200);
        g.setColor(new Color(109, 64, 180));
        g.drawRect(300,300,100,100);
        //养成习惯,画笔用完换回最初的颜色
    }
}

8、鼠标监听

目的:实现鼠标画画
在运行完MyFrame以及鼠标事件后,最后才运行画笔的方法

public class TestMouseListener {
    public static void main(String[] args) {
new MyFrame("title");
    }
}
class MyFrame extends Frame{
    //画画需要画笔,需要当前的位置,需要集合储存
    ArrayList points;
    public MyFrame (String title){
        super(title);
        setBounds(100,100,500,400);
        setVisible(true);
        //存鼠标单击的点
        points = new ArrayList();
        //鼠标监听器正对这个窗口
        this.addMouseListener(new MyMouseListener());
    }
    @Override
    public void paint(Graphics g) {
        //画画,监听鼠标的事件
        Iterator iterator = points.iterator();
        while (iterator.hasNext()){
            Point point = (Point) iterator.next();
            g.setColor(new Color(22, 138, 175));
            g.fillOval(point.x,point.y,10,10);
        }
    }
    public void addPaint(Point point){
        points.add(point);
    }
    private class MyMouseListener extends MouseAdapter{
        //鼠标 按下,弹起,按住不放
        @Override
        public void mousePressed(MouseEvent e) {
            MyFrame frame = (MyFrame) e.getSource();
            //这个我们点击的时候就会在上面产生一个点。画
            //这个点就是鼠标的点
            frame.addPaint(new Point(e.getX(),e.getY()));
            //每次点击鼠标需要重画一次
            frame.repaint();//刷新  帧
        }
    }
}

9、窗口监听

窗口事件可以不创建对象直接使用。

public class TestWindow {
    public static void main(String[] args) {
new WindowFrame();
    }
}
class WindowFrame extends Frame{
    public WindowFrame(){
        setBounds(100,100,300,300);
        setVisible(true);
        this.addWindowListener(
                new WindowAdapter() {
                    //关闭窗口
                    @Override
                    public void windowClosing(WindowEvent e) {
                        System.out.println("点击关闭");
                        System.exit(0);
                    }
                    //激活窗口
                    @Override
                    public void windowActivated(WindowEvent e) {
                        WindowFrame windowFrame = (WindowFrame) e.getSource();
                        windowFrame.setTitle("激活");
                        System.out.println("激活");
                    }
                }
        );
    }
}

10、键盘监听

public class TestKeyListener {
    public static void main(String[] args) {
new MyKeyListener();
    }
}
class MyKeyListener extends Frame{
    public MyKeyListener(){
        setBounds(100,100,500,400);
        setVisible(true);
        this.addKeyListener(
                new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        int keycode= e.getKeyCode();
                        System.out.println(keycode);
                        if(keycode == KeyEvent.VK_UP){
                            System.out.println("你按下了上键");
                        }
                    }
                }
        );
    }
}

3、Swing

URL用法
getResource("") //表示同级目录下的文件 如:
file:/E:/classes/testpackage/
getResource("/") //表示上一级目录 如:
file:/E:/classes/

1、窗口、面板

public class JFrameDemo01 {
    public static void main(String[] args) {
new MyJFrame().init();
    }
}
class MyJFrame extends JFrame{
    public void init(){
        //顶级窗口
        JFrame jFrame = new JFrame();
        jFrame.setVisible(true);
        jFrame.setBounds(100,100,300,300);
        //标签
        JLabel jLabel = new JLabel("aa");
        jFrame.add(jLabel);
        jLabel.setHorizontalAlignment(SwingConstants.CENTER);
        jFrame.getContentPane().setBackground(Color.CYAN);
        //关闭事件
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
}

2、弹窗

JDialog弹窗的窗口默认有关闭事件,不需要写关闭事件。

public class DialogDemo {
    public static void main(String[] args) {
        new MyDialogDemo();
    }
}
class MyDialogDemo extends JFrame{
    public MyDialogDemo(){
        this.setBounds(10,10,500,500);
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //JFrame放东西的容器
        Container contentPane = this.getContentPane();
        //按钮
        JButton jButton = new JButton("点击弹出一个弹窗");
        jButton.setBounds(100,100,200,50);
        //绝对布局
        contentPane.setLayout(null);
        //添加按钮
        contentPane.add(jButton);
        //点击按钮出现弹窗
        jButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        //弹窗
                        new MyDialog();
                    }
                });
    }
}
//弹窗的窗口
class MyDialog extends JDialog{
    public MyDialog(){
        this.setVisible(true);
        this.setBounds(100,100,200,200);
        Container contentPane = this.getContentPane();
        contentPane.setLayout(null);
        contentPane.add(new Label("弹窗"));
    }
}

3、标签

图标标签:图标(ICON)

public class ImageIconDemo extends JFrame {
    public ImageIconDemo(){
        JLabel jLabel = new JLabel("ImageIcon");
        URL url = ImageIconDemo.class.getResource("tp.jpg");
        ImageIcon imageIcon = new ImageIcon(url);
        jLabel.setIcon(imageIcon);
        jLabel.setHorizontalAlignment(SwingConstants.CENTER);
        Container contentPane = getContentPane();
        contentPane.add(jLabel);
        setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setBounds(10,10,400,400);
    }
    public static void main(String[] args) {
        new ImageIconDemo();
    }
}

4、面板

JPanel

public class JPanelDemo extends JFrame {
    public JPanelDemo(){
        Container contentPane = this.getContentPane();
        contentPane.setLayout(new GridLayout(2,1,10,10));//后面的参数是间距
        //面板
        JPanel jPanel1 = new JPanel(new GridLayout(1,2));
        JPanel jPanel2 = new JPanel(new GridLayout(2,1));
        JPanel jPanel3 = new JPanel(new GridLayout(3,1));
        JPanel jPanel4 = new JPanel(new GridLayout(1,3));
        jPanel1.add(new Button("1"));
        jPanel1.add(new Button("1"));
        jPanel2.add(new Button("2"));
        jPanel2.add(new Button("2"));
        jPanel3.add(new Button("3"));
        jPanel3.add(new Button("3"));
        jPanel3.add(new Button("3"));
        jPanel4.add(new Button("4"));
        jPanel4.add(new Button("4"));
        jPanel4.add(new Button("4"));
        //添加
        contentPane.add(jPanel1);
        contentPane.add(jPanel2);
        contentPane.add(jPanel3);
        contentPane.add(jPanel4);
        this.setVisible(true);
        this.setBounds(100,100,400,400);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        new JPanelDemo();
    }
}

JScrollPanel、文本域

带下拉条的面板

public class JScrollPanelDemo extends JFrame {
    public JScrollPanelDemo() {
        Container contentPane = this.getContentPane();
        //文本域
        JTextArea jTextarea = new JTextArea(20,50);
        jTextarea.setText("aaaa");
        //Scroll面板
        JScrollPane jScrollPane = new JScrollPane(jTextarea);
        contentPane.add(jScrollPane);
        this.setVisible(true);
        this.setBounds(100,100,300,300);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        new JScrollPanelDemo();
    }
}

5、按钮

图片按钮

public class JButtonDemo01 extends JFrame {

    public JButtonDemo01 (){
        Container contentPane = this.getContentPane();

        //将一个图片变为图标
        URL url = JButtonDemo01.class.getResource("tp1.jpg");
        Icon icon = new ImageIcon(url);

        //将图标放在按钮上
        JButton jButton = new JButton();
        jButton.setIcon(icon);
        jButton.setToolTipText("图片按钮");

        //添加
        contentPane.add(jButton);

        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setBounds(100,100,400,400);

    }

    public static void main(String[] args) {
        new JButtonDemo01();
    }
}

单选按钮

public class JButtonDemo02 extends JFrame {

    public JButtonDemo02(){
        Container contentPane = this.getContentPane();

        URL url = JButtonDemo02.class.getResource("tp1.jpg");
        Icon icon = new ImageIcon(url);

        //单选按钮
        JRadioButton radioButton1 = new JRadioButton("radioButton1");
        JRadioButton radioButton2 = new JRadioButton("radioButton2");
        JRadioButton radioButton3 = new JRadioButton("radioButton3");
        //分组,每组只能选一个
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(radioButton1);
        buttonGroup.add(radioButton2);
        buttonGroup.add(radioButton3);

        //add
        contentPane.add(radioButton1,BorderLayout.CENTER);
        contentPane.add(radioButton2,BorderLayout.NORTH);
        contentPane.add(radioButton3,BorderLayout.SOUTH);

        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setBounds(100,100,400,400);

    }

    public static void main(String[] args) {
        new JButtonDemo02();
    }
}

多选按钮

public class JButtonDemo03 extends JFrame {

    public JButtonDemo03(){
        Container contentPane = this.getContentPane();

        URL url = JButtonDemo03.class.getResource("tp1.jpg");
        Icon icon = new ImageIcon(url);

        //多选框
        JCheckBox jCheckBox1 = new JCheckBox("1");
        JCheckBox jCheckBox2 = new JCheckBox("2");
        //添加
        contentPane.add(jCheckBox1,BorderLayout.NORTH);
        contentPane.add(jCheckBox2,BorderLayout.SOUTH);

        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setBounds(100,100,400,400);

    }

    public static void main(String[] args) {
        new JButtonDemo03();
    }
}

6、列表

下拉框

public class TestComboboxDemo01 extends JFrame {
    public TestComboboxDemo01(){
        Container contentPane = this.getContentPane();

        JPanel jPanel = new JPanel();

        JComboBox jComboBox = new JComboBox();
        jComboBox.addItem(null);
        jComboBox.addItem("a");
        jComboBox.addItem("b");
        jComboBox.addItem("c");

        jPanel.add(jComboBox);
        contentPane.add(jPanel);

        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setBounds(100,100,400,400);
    }

    public static void main(String[] args) {
        new TestComboboxDemo01();
    }
}

列表框

用来展示信息,一般是动态扩容

public class TestComboboxDemo02 extends JFrame {
    public TestComboboxDemo02(){
        Container contentPane = this.getContentPane();

        //静态
        String[] contents = {"a","b","c","c","c","c","c","c","c","c","c"};
        //动态集合,可以实现列表的动态删减
        Vector vector = new Vector();
        vector.add("aa");
        vector.add("aa");
        vector.add("aa");
        vector.add("aa");

//JList jList1 = new JList(contents);
        JList jList = new JList(vector);
        JScrollPane jPanel = new JScrollPane(jList);
        contentPane.add(jPanel);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setBounds(100,100,400,200);
    }

    public static void main(String[] args) {
        new TestComboboxDemo02();
    }
}

7、文本框

文本框

public class TestTextDemo01 extends JFrame{
    public TestTextDemo01(){
        Container contentPane = this.getContentPane();

        JTextField jTextField1 = new JTextField("aaa");
        JTextField jTextField2 = new JTextField("123456",5);
        contentPane.add(jTextField1,BorderLayout.SOUTH);
        contentPane.add(jTextField2,BorderLayout.NORTH);

        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setBounds(100,100,400,400);
    }

    public static void main(String[] args) {
        new TestTextDemo01();
    }
}

密码框

public class TestTextDemo02 extends JFrame {
    public static void main(String[] args) {
        new TestTextDemo02();
    }
    public TestTextDemo02(){
        Container contentPane = this.getContentPane();

        JPasswordField jPasswordField = new JPasswordField();
        jPasswordField.setEchoChar('*');
        contentPane.add(jPasswordField);

        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setBounds(100,100,400,400);
    }
}
posted @ 2022-04-09 20:26  星星淮  阅读(371)  评论(0)    收藏  举报