Java图形界面04【一个失败的项目】/byme
程序员文章站
2024-03-19 08:16:46
...
Code:
package lp_2018_02_08_01;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class newWindow implements WindowListener {
@Override
public void windowOpened(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
// get now window [获取当前窗口]
Window window = e.getWindow();
// setting now window can't see [设置当前窗口不可见]
window.setVisible(false);
//dispose now window [注销当前窗口]
window.dispose();
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
}
package lp_2018_02_08_01;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class newMonse implements MouseListener {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
}
package lp_2018_02_08_01;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class thisDomon01 {
//窗体对象 window object
private Frame lpFrame;
//按钮对象 button object
private Button lpButton01;
//文本输入对象
private TextField lpTextFieldForInput;
//文本输出对象
private TextArea lpTextAreaForOutput;
//容器对象
private Panel lpPanelForInputAndButton;
public thisDomon01() {
//实例化窗体对象
lpFrame = new Frame();
lpFrame.setLayout(new BorderLayout());
lpFrame.addWindowListener(new newWindow());
lpFrame.addMouseListener(new newMonse());
lpFrame.setSize(800,500);
lpFrame.setLocation(200,200);
lpButton01 = new Button("OK");
lpButton01.setName("OK");
lpTextAreaForOutput = new TextArea(700,450);
lpTextAreaForOutput.setEditable(false);
lpTextFieldForInput = new TextField(30);
lpPanelForInputAndButton = new Panel();
lpPanelForInputAndButton.add(lpTextFieldForInput);
lpPanelForInputAndButton.add(lpButton01);
lpFrame.add(lpPanelForInputAndButton);
lpFrame.add(lpTextAreaForOutput, BorderLayout.CENTER);
lpFrame.add(lpPanelForInputAndButton, BorderLayout.SOUTH);
}
public void buttonAddAction() {
lpButton01.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String strInformation = lpTextFieldForInput.getText();
if (strInformation == "" || strInformation == null) {
;
}else {
lpTextAreaForOutput.append("\n" + strInformation);
lpTextFieldForInput.setText("");
}
}
});
}
public void test() {
lpButton01.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String str = lpTextFieldForInput.getText();
if (str == "" || str == null) {
lpTextAreaForOutput.append("\n" + "你的名字:");
lpButton01.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String strName = lpTextFieldForInput.getText();
if (strName == "" || strName == null) {
;
}
else {
if (strName == "NULL") {
lpTextAreaForOutput.append("\n" + "Right!");
lpTextFieldForInput.setText("");
}
else {
lpTextAreaForOutput.append("\n" + "Worry!");
lpTextFieldForInput.setText("");
}
}
}
});
}
else {
lpButton01.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String strInformation = lpTextFieldForInput.getText();
if (strInformation == "" || strInformation == null) {
;
}else {
lpTextAreaForOutput.append("\n" + strInformation);
lpTextFieldForInput.setText("");
}
}
});
}
}
});
}
public void show() {
//this.buttonAddAction();
this.test();
lpFrame.setVisible(true);
}
}
package lp_2018_02_08_01;
public class Domon {
public static void main(String [] args) {
thisDomon01 lp_a = new thisDomon01();
lp_a.show();
}
}
Effect :
上一篇: 嘿!你还是那个追梦少年吗?(序)
下一篇: SSL 2386 序列#线性动态规划#