java 可视化界面编程
importjava.awt.*;importjava.awt.event.*;importjava.awt.Frame;publicclassawttest{publi...
import java.awt.*;
import java.awt.event.*;
import java.awt.Frame;
public class awttest
{
public static void main(String[] args)
{
Frame f=new Frame("用户登录");
f.setLayout(new GridLayout(4,2));
TextField id=new TextField("输入用户名",10);
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("登陆");
Button b2=new Button("取消");
f.add(b1);
f.add(b2);
String str1=id.getText();
String str2=pw.getText();
TextField printid=new TextField(str1,10);
TextField 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);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent args)
{
System.exit(0);
}
}
);
}
}
刚刚写了个java可视化界面 现在想实现 两个Button的功能,当鼠标或者键盘确认登陆键的时候,用户输入的用户名和密码显示在printid和printpw两个TextField里面。望高手指教··谢谢
还有当鼠标按取消Button的时候 实现跟WindowListener一样的退出关闭功能。 展开
import java.awt.event.*;
import java.awt.Frame;
public class awttest
{
public static void main(String[] args)
{
Frame f=new Frame("用户登录");
f.setLayout(new GridLayout(4,2));
TextField id=new TextField("输入用户名",10);
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("登陆");
Button b2=new Button("取消");
f.add(b1);
f.add(b2);
String str1=id.getText();
String str2=pw.getText();
TextField printid=new TextField(str1,10);
TextField 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);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent args)
{
System.exit(0);
}
}
);
}
}
刚刚写了个java可视化界面 现在想实现 两个Button的功能,当鼠标或者键盘确认登陆键的时候,用户输入的用户名和密码显示在printid和printpw两个TextField里面。望高手指教··谢谢
还有当鼠标按取消Button的时候 实现跟WindowListener一样的退出关闭功能。 展开
展开全部
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!!可以运行
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!!可以运行
展开全部
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);
}
});
}
}
加入修改部分
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);
}
});
}
}
加入修改部分
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询