欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java第二十八课时

程序员文章站 2022-07-14 19:57:01
...

1文本框
2事件的类型和处理方法-键盘监听,鼠标监听
package com.hg.day28.demo01;

import javax.swing.;
import java.awt.
;

public class TestTextDemo02 extends JFrame {
public TestTextDemo02(){
Container container = this.getContentPane();
JPasswordField passwordField = new JPasswordField();
passwordField.setEchoChar(’#’);
container.add(passwordField);
Label label = new Label();
// JTextField textField = new JTextField(“hello world”);
// JTextField textField2 = new JTextField(“大数据五班”);
// container.add(textField,BorderLayout.NORTH);
// container.add(textField2,BorderLayout.SOUTH);

    this.setVisible(true);
    this.setSize(500,350);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
    new TestTextDemo02();
}

}

package com.hg.day28.demo02;

import javax.swing.;
import java.awt.
;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TextActionEvent {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(400,400);
frame.locate(400,300);

    MyActionListener myListener = new MyActionListener();
    Button button= new Button();
    button.addActionListener(myListener);
    frame.add(button,BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

}

}
class MyActionListener implements ActionListener {

@Override
public void actionPerformed(ActionEvent e) {
    System.out.println("大数据五班");
}

}