Java学习
首先
package glc;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class TestTextGlc extends JFrame {
public TestTextGlc() {
Container container=this.getContentPane();
JTextField textfield=new JTextField(“Hello wrold”);
JTextField textfield2=new JTextField(“大数据五班”);
container.add(textfield,BorderLayout.NORTH);
container.add(textfield2,BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(500,350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestTextGlc();
}
}
package demo01;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class TestText1 extends JFrame{
public TestText1() {
Container container=this.getContentPane();
JPasswordField passwordfield=new JPasswordField();
passwordfield.setEchoChar(’^’);
container.add(passwordfield);
this.setVisible(true);
this.setSize(500,350);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestText1();
}
}
package glc1;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class TextActionEvent {
public static void main(String[] args) {
JFrame frame=new JFrame();
frame.setSize(400,400);
frame.locate(400, 300);
MyActionListener myActionListener=new MyActionListener();
Button button=new Button();
button.addActionListener(myActionListener);
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(“大数据五班”);
}
}
package demo02;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class TextActionEvent {
public static void main(String[] args) {
JFrame frame =new JFrame();
frame.setSize(400,400);
frame.locate(400, 300);
MyActionListener myActionListener=new MyActionListener();
Button button =new Button();
button.addActionListener(myActionListener);
frame.add(button);
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("2005");
}
}
package glc2;
import java.awt.Color;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class TextWindow {
public static void main(String[] args) {
new WindowFrame();
}
}
class WindowFrame extends JFrame{
public WindowFrame() {
this.setBackground(Color.blue);
this.setBounds(100,100,500,500);
this.setVisible(true);
//this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//this.addWindowFocusListener(new MyWindowListener());
this.addWindowListener(
//匿名内部类
new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
setVisible(false);//设置不可见
System.out.println(“我要关闭”);
//System.exit(0);
}@Override
public void windowActivated(WindowEvent e) {
super.windowActivated(e);
System.out.println(“windowActivated”);
}@Override
public void windowClosed(WindowEvent e) {
//super.windowClosed(e);
System.out.println(“windowClosed”);
}@Override
public void windowOpened(WindowEvent e) {
//super.windowOpened(e);
System.out.println(“windowOpened”);
}
}
);
}
}
/*
class MyWindowListener extends MyWindowListener{
//按住alt + /
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);//设置不可见
System.out.println(“我要关闭”);
//System.exit(0);
}
}*/