现在有这样一段代码
public class Login{
public static void main(String args[]){
EventQueue.invokeLater(new Runnable()
{
public void run(){
LoginFrame Frame=new LoginFrame();
Frame.setVisible(true);
}
});
}
}
class LoginFrame extends JFrame {
ImageIcon snow=new ImageIcon("src.jpg");
JTextField TextField1 = new JTextField(10);
JButton Button1 = new JButton();
JButton Button2 = new JButton();
JButton Button3= new JButton();
JPasswordField PasswordField = new JPasswordField(10);
JPanel Panel= new JPanel();
JLabel Label1=new JLabel("账号");
JLabel Label2=new JLabel("密码");
public LoginFrame(){
setBounds(444,220, 444, 555);
setResizable(false);
setSize(350,250);
panel();
}
public void panel(){
Button1.setText("注册");
Button1.addActionListener(new Button1Listener());
Button2.setText("找回");
Button2.addActionListener(new Button2Listener());
Button3.setText("登陆");
Button3.addActionListener(new Button3Listener());
TextField1.setText("");
Panel.add(Label1);
Panel.add(Label2);
Panel.add(Button1);
Panel.add(Button2);
Panel.add(Button3);
Panel.add(PasswordField);
Panel.add(TextField1);
add(Panel);
}
请问怎样把组件布置成这样啊 账号 TextField的位置 注册
密码 JPassword的位置 找回 登陆显示在中间。路过的帮帮忙啊 憔悴死偶了~~
public class Login{
public static void main(String args[]){
EventQueue.invokeLater(new Runnable()
{
public void run(){
LoginFrame Frame=new LoginFrame();
Frame.setVisible(true);
}
});
}
}
class LoginFrame extends JFrame {
ImageIcon snow=new ImageIcon("src.jpg");
JTextField TextField1 = new JTextField(10);
JButton Button1 = new JButton();
JButton Button2 = new JButton();
JButton Button3= new JButton();
JPasswordField PasswordField = new JPasswordField(10);
JPanel Panel= new JPanel();
JLabel Label1=new JLabel("账号");
JLabel Label2=new JLabel("密码");
public LoginFrame(){
setBounds(444,220, 444, 555);
setResizable(false);
setSize(350,250);
panel();
}
public void panel(){
Button1.setText("注册");
Button1.addActionListener(new Button1Listener());
Button2.setText("找回");
Button2.addActionListener(new Button2Listener());
Button3.setText("登陆");
Button3.addActionListener(new Button3Listener());
TextField1.setText("");
Panel.add(Label1);
Panel.add(Label2);
Panel.add(Button1);
Panel.add(Button2);
Panel.add(Button3);
Panel.add(PasswordField);
Panel.add(TextField1);
add(Panel);
}
请问怎样把组件布置成这样啊 账号 TextField的位置 注册
密码 JPassword的位置 找回 登陆显示在中间。路过的帮帮忙啊 憔悴死偶了~~
解决方案 »
- 如何忽略BufferedReader的readLine()读到的中间多个空格
- 求教Thread线程的小问题
- Jtable双击弹出窗口
- 奇怪, \u000a被识别为: 未结束的字符串字面值
- int类型 如何 转换为 String类型
- JSP 中访问数据库,如果查询的是多个表,那么RS.get..()中怎么确定类啊?
- 生成执行文件的问题?
- 那位高人传授一下在Linux下安装JBuilder经验,高分呈上!!!!
- 一个ServerSocket服务端在同一个端口上并发连接N个客户端
- 自定义公式计算
- 请教一个问题jdk1.5的File.delete()方法为何不能删除文件呢?
- dom写xml中文乱码问题,急急急
画个草图,大概计算下你的每个label,button,textfield的四个参数就OK了
public class Login extends JFrame { private JPanel contentPane;
private JTextField textField;
private JPasswordField passwordField; /**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TestLogin frame = new TestLogin();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} /**
* Create the frame.
*/
public TestLogin() {
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
setSize(350, 194);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new GridLayout(0, 1, 0, 0));
JPanel panel = new JPanel();
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
contentPane.add(panel);
Component horizontalStrut_1 = Box.createHorizontalStrut(40);
panel.add(horizontalStrut_1);
JLabel label = new JLabel("账号:");
panel.add(label);
textField = new JTextField();
panel.add(textField);
textField.setColumns(10);
Component horizontalStrut = Box.createHorizontalStrut(20);
panel.add(horizontalStrut);
JButton button = new JButton("注册");
panel.add(button);
JPanel panel_1 = new JPanel();
FlowLayout flowLayout_1 = (FlowLayout) panel_1.getLayout();
flowLayout_1.setAlignment(FlowLayout.LEFT);
contentPane.add(panel_1);
Component horizontalStrut_2 = Box.createHorizontalStrut(20);
horizontalStrut_2.setPreferredSize(new Dimension(40, 0));
panel_1.add(horizontalStrut_2);
JLabel label_1 = new JLabel("密码:");
panel_1.add(label_1);
passwordField = new JPasswordField();
passwordField.setColumns(10);
panel_1.add(passwordField);
Component horizontalStrut_3 = Box.createHorizontalStrut(20);
panel_1.add(horizontalStrut_3);
JButton button_1 = new JButton("找回");
panel_1.add(button_1);
JPanel panel_2 = new JPanel();
FlowLayout flowLayout_2 = (FlowLayout) panel_2.getLayout();
flowLayout_2.setAlignment(FlowLayout.LEFT);
contentPane.add(panel_2);
Component horizontalStrut_4 = Box.createHorizontalStrut(20);
horizontalStrut_4.setPreferredSize(new Dimension(40, 0));
panel_2.add(horizontalStrut_4);
JButton button_2 = new JButton("登录");
panel_2.add(button_2);
}}
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import java.awt.Dimension;
import javax.swing.SwingConstants;public class ssssssss extends JPanel { private static final long serialVersionUID = 1L;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JTextField jTextField = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JPasswordField jPasswordField = null;
private JButton jButton2 = null;
/**
* This is the default constructor
*/
public ssssssss() {
super();
initialize();
} /**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.gridy = 0;
gridBagConstraints6.gridx = 0;
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.gridx = 1;
gridBagConstraints5.gridy = 2;
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.fill = GridBagConstraints.NONE;
gridBagConstraints4.gridy = 1;
gridBagConstraints4.gridx = 1;
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.gridx = 2;
gridBagConstraints3.gridy = 1;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 2;
gridBagConstraints2.gridy = 0;
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = 1;
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridx = 1;
jLabel1 = new JLabel();
jLabel1.setText("账户:");
jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel1.setPreferredSize(new Dimension(46, 18));
this.setSize(252, 129);
this.setLayout(new GridBagLayout());
this.add(jLabel1, new GridBagConstraints());
this.add(getJLabel2(), gridBagConstraints1);
this.add(getJTextField(), gridBagConstraints);
this.add(getJButton(), gridBagConstraints2);
this.add(getJButton1(), gridBagConstraints3);
this.add(getJPasswordField(), gridBagConstraints4);
this.add(getJButton2(), gridBagConstraints5);
} /**
* This method initializes jLabel2
*
* @return javax.swing.JLabel
*/
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("密码:");
jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel2.setPreferredSize(new Dimension(46, 18));
}
return jLabel2;
} /**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setPreferredSize(new Dimension(80, 22));
}
return jTextField;
} /**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("注册");
}
return jButton;
} /**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("找回");
}
return jButton1;
} /**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setPreferredSize(new Dimension(80, 22));
}
return jPasswordField;
} /**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setText("登陆");
}
return jButton2;
}}