java 可视化界面编程

发布网友 发布时间:2022-04-20 13:55

我来回答

2个回答

热心网友 时间:2023-07-14 21:19

import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class awttest
{
TextField id,pw;
TextField printid,printpw;

public awttest(){
Frame f=new Frame("用户登录");
f.setLayout(new GridLayout(4,2));
id=new TextField("输入用户名",10);
pw=new TextField(10);
pw.setEchoChar('*');
f.add(new Label("用户名:",Label.CENTER));
f.add(id);
f.add(new Label("密码:",Label.CENTER));
f.add(pw);
Button b1=new Button("登陆");
Button b2=new Button("取消");
f.add(b1);
f.add(b2);
String str1=id.getText();
String str2=pw.getText();
printid=new TextField(str1,10);
printpw=new TextField(str2,10);
f.add(printid);
f.add(printpw);
f.pack();

printid.setBackground(new Color(220,0,0));
printpw.setBackground(new Color(220,0,0));
f.setSize(250,120);
f.setVisible(true);

b1.addActionListener(new ActionListener() { // 点击“显示窗口”菜单后将窗口显示出来
public void actionPerformed(ActionEvent e) {
printid.setText(id.getText());
printpw.setText(pw.getText());

}
});

f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent args)
{
System.exit(0);
}
}
);
}

public static void main(String[] args){
new awttest();

}

}

OK!!可以运行

热心网友 时间:2023-07-14 21:19

import java.awt.*;
import java.awt.event.*;
import java.awt.Frame;

public class TransIntToDate {
public static void main(String[] args) {
Frame f = new Frame("用户登录");
f.setLayout(new GridLayout(4, 2));
final TextField id = new TextField("输入用户名", 10);
final TextField pw = new TextField(10);
pw.setEchoChar('*');
f.add(new Label("用户名:", Label.CENTER));
f.add(id);
f.add(new Label("密码:", Label.CENTER));
f.add(pw);
Button b1 = new Button("登陆");
String str1 = id.getText();
String str2 = pw.getText();
final TextField printid = new TextField(str1, 10);
final TextField printpw = new TextField(str2, 10);
// //----------
b1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
printid.setText(id.getText());
printpw.setText(pw.getText());
}

});
// //----------
Button b2 = new Button("取消");
f.add(b1);
f.add(b2);

f.add(printid);
f.add(printpw);
f.pack();

printid.setBackground(new Color(220, 0, 0));
printpw.setBackground(new Color(220, 0, 0));
f.setSize(250, 120);
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent args) {
System.exit(0);
}
});
}
}
加入修改部分

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com