2021-06-19

17 篇文章 0 订阅

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);
}
}*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值