java第二十八课时
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("大数据五班");
}
}
上一篇: day3 运算符和字符串
下一篇: Day3—字符串