怎么样设计一个图形用户界面(普通登陆框)用java语言中的swing
1、用户名.密码为标签(JLabel或Label)2、用户名输入项为文本框(JTextField)3、密码输入项为密码框(JPasswordField)4、确定、取消为按...
1、用户名.密码为标签(JLabel或Label)2、用户名输入项为文本框(JTextField)3、密码输入项为密码框(JPasswordField)4、确定、取消为按钮项(JBatton)5、按钮不用响应事件
展开
2个回答
2013-09-05
展开全部
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Test6 extends JFrame{
private JPanel textpane = new JPanel();
private JLabel username = new JLabel("用户名:");
private JLabel password = new JLabel("密 码:");
private JPanel inputpane= new JPanel();
private JTextField usernameinput = new JTextField(14);
private JPasswordField passwordinput = new JPasswordField(14);
private JPanel btnpane = new JPanel();
private JButton sure = new JButton("确定");
private JButton back = new JButton("取消");
public Test6(){
super("登陆框");
//西部放置文字
textpane.setLayout(new GridLayout(0,1));
textpane.add(username);
textpane.add(password);
add(textpane,BorderLayout.WEST);
//中部放置输入
inputpane.setLayout(new GridLayout(0,1));
inputpane.add(usernameinput);
inputpane.add(passwordinput);
add(inputpane);
//南部放置按钮
btnpane.setLayout(new GridLayout(0,2));
btnpane.add(sure);
btnpane.add(back);
add(btnpane,BorderLayout.SOUTH);
//基本设置
pack();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screen.width - getWidth()) / 2,(screen.height - getHeight()) / 2);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
new Test6();
}
}
//如你所需,没有加监听,需要的话,我再加
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Test6 extends JFrame{
private JPanel textpane = new JPanel();
private JLabel username = new JLabel("用户名:");
private JLabel password = new JLabel("密 码:");
private JPanel inputpane= new JPanel();
private JTextField usernameinput = new JTextField(14);
private JPasswordField passwordinput = new JPasswordField(14);
private JPanel btnpane = new JPanel();
private JButton sure = new JButton("确定");
private JButton back = new JButton("取消");
public Test6(){
super("登陆框");
//西部放置文字
textpane.setLayout(new GridLayout(0,1));
textpane.add(username);
textpane.add(password);
add(textpane,BorderLayout.WEST);
//中部放置输入
inputpane.setLayout(new GridLayout(0,1));
inputpane.add(usernameinput);
inputpane.add(passwordinput);
add(inputpane);
//南部放置按钮
btnpane.setLayout(new GridLayout(0,2));
btnpane.add(sure);
btnpane.add(back);
add(btnpane,BorderLayout.SOUTH);
//基本设置
pack();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screen.width - getWidth()) / 2,(screen.height - getHeight()) / 2);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
new Test6();
}
}
//如你所需,没有加监听,需要的话,我再加
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-05
展开全部
用C#,超级简单!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |