编写一个java小程序
编写一个小程序,用文本框接受用户的用户名和密码,如果用户名和密码是javalearner和happy,则输出“javahappy”....
编写一个小程序,用文本框接受用户的用户名和密码,如果用户名和密码是javalearner和happy,则输出“javahappy”.
展开
展开全部
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class TestSwg extends JFrame
{
private JLabel username;
private JLabel password;
private JTextField userField;
private JTextField passField;
private JButton submit;
private JLabel result;
public TestSwg(){
username = new JLabel("用户名:");
password = new JLabel("密码:");
userField = new JTextField();
userField.setPreferredSize(new Dimension(120,20));
passField = new JTextField();
passField.setPreferredSize(new Dimension(120,20));
submit = new JButton("提交");
result = new JLabel("结果");
this.add(username);
this.add(userField);
this.add(password);
this.add(passField);
this.add(submit);
this.add(result);
this.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
this.setBounds(100, 100, 200, 200);
this.setVisible(true);
submit.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(userField.getText().equals("javalearner") && passField.getText().equals("happy")){
result.setText("javahappy");
}else{
result.setText("error data");
}
}
});
}
public static void main(String [] args){
TestSwg ts = new TestSwg();
}
}
自己写得很辛苦请采纳
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class TestSwg extends JFrame
{
private JLabel username;
private JLabel password;
private JTextField userField;
private JTextField passField;
private JButton submit;
private JLabel result;
public TestSwg(){
username = new JLabel("用户名:");
password = new JLabel("密码:");
userField = new JTextField();
userField.setPreferredSize(new Dimension(120,20));
passField = new JTextField();
passField.setPreferredSize(new Dimension(120,20));
submit = new JButton("提交");
result = new JLabel("结果");
this.add(username);
this.add(userField);
this.add(password);
this.add(passField);
this.add(submit);
this.add(result);
this.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
this.setBounds(100, 100, 200, 200);
this.setVisible(true);
submit.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(userField.getText().equals("javalearner") && passField.getText().equals("happy")){
result.setText("javahappy");
}else{
result.setText("error data");
}
}
});
}
public static void main(String [] args){
TestSwg ts = new TestSwg();
}
}
自己写得很辛苦请采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |