我无法将jlabels移动到我的面板/ GUI java代码上的正确位置

时间:2014-05-02 16:02:21

标签: java user-interface jlabel bluej

我使用BlueJ创建了一个面板/ GUI,其中包含多个JLabel和Entry框以及一个按钮,但是当我执行它时,标签彼此相邻,并且Confirm按钮出现在与最后一个输入框相同的行上,香港专业教育学院尝试更改代码中的坐标,但它没有什么区别,我将如何让自己的输入框旁边的每个标签和应用程序底部的确认按钮?

我的代码如下:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class Log extends JFrame {

    public static void main(String[] args){
        Log frameTable1= new Log();
    }

JPanel panel = new JPanel();
JLabel name = new JLabel("Name", JLabel.LEFT);
JTextField FullName = new JTextField(15);
JPanel panel1 = new JPanel();
JLabel address = new JLabel("Address", JLabel.LEFT);
JTextField Address1line = new JTextField(15);
JTextField postcode = new JTextField(15);
JTextField Destination = new JTextField(15);
JTextField Date = new JTextField(15);
JTextField MilesTravelling = new JTextField(15);
JButton Confirm = new JButton("Confirm");

Log(){
    super("Customer GUI");
    setSize(300,400);
    setLocation(400,250);
    panel.setLayout(new FlowLayout());

    FullName.setBounds(70,30,150,20);
    Address1line.setBounds(70,80,150,20);
    postcode.setBounds(70,130,150,20);
    Destination.setBounds(70,180,150,20);
    Date.setBounds(70,230,150,20);
    MilesTravelling.setBounds(70,280,150,20);
    Confirm.setBounds(105,290,80,40);
    name.setBounds(40,30,150,20);
    address.setBounds(40, 80, 150, 20);

    getContentPane().add(name);
    getContentPane().add(panel);
    panel.add(name);
    getContentPane().add(address);
    getContentPane().add(panel);
    panel.add(address);
    panel.add(FullName);             
    panel.add(Address1line);
    panel.add(postcode);
    panel.add(Destination);
    panel.add(Date);
    panel.add(MilesTravelling);
    panel.add(Confirm);

    getContentPane().add(panel);        
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

    }
}

三江源

0 个答案:

没有答案