[我正在尝试创建一个如下图所示的布局。我是Java编程的新手。]当我试图运行它时。没有任何错误或任何内容,也没有任何显示。控制台自动停止。请帮助我。
package completeJavaReference;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
------------------------------------------------------------------------
public class tryingProject extends JFrame {
public static final long serialVersionUID = 1L;//Eclipse added
public static JLabel carname;
public static JLabel price, make, year, trim, category, VIN, model,bodytype;
public static JLabel dealerinfo, ID, URL, Name;
public static JTextField priceTextField, makeTextField, yearTextField,
trimTextField, categoryTextField, VINTextField, modelTextField,
bodytypeTextField;
private static JTextField dealerinfoTextField, IDTextField, URLTextField,
NameTextField;
public void createComponents() {
carname = new JLabel("Honda Civic");
price = new JLabel("Price: ");
make = new JLabel("Make: ");
year = new JLabel("Year:");
trim = new JLabel("Trim:");
category = new JLabel("Category:");
VIN = new JLabel("VIN:");
model = new JLabel("Model:");
bodytype = new JLabel("Body Type");
priceTextField = new JTextField(10);
makeTextField = new JTextField(10);
yearTextField = new JTextField(10);
trimTextField = new JTextField(10);
categoryTextField = new JTextField(10);
VINTextField = new JTextField(10);
modelTextField = new JTextField(10);
bodytypeTextField = new JTextField(10);
dealerinfo = new JLabel("Dealer Info");
ID = new JLabel("Dealer ID:");
URL = new JLabel("URL:");
Name = new JLabel("Dealer Name");
dealerinfoTextField = new JTextField(10);
IDTextField = new JTextField(10);
URLTextField = new JTextField(10);
NameTextField = new JTextField(10);
}
public void createLayout(){
JFrame frame = new JFrame("Vehicle Window");
JPanel Panel1 = new JPanel(new FlowLayout());
JPanel Panel2 = new JPanel(new GridLayout(4, 3));
JPanel Panel3 = new JPanel(new FlowLayout());
Panel1.add(carname);
Panel2.add(price);
Panel2.add(priceTextField);
Panel2.add(make);
Panel2.add(makeTextField);
Panel2.add(year);
Panel2.add(yearTextField);
Panel2.add(trim);
Panel2.add(trimTextField);
Panel2.add(category);
Panel2.add(categoryTextField);
Panel2.add(VIN);
Panel2.add(VINTextField);
Panel2.add(model);
Panel2.add(modelTextField);
Panel2.add(year);
Panel2.add(yearTextField);
Panel3.add(dealerinfo);
Panel3.add(dealerinfoTextField);
Panel3.add(ID);
Panel3.add(IDTextField);
Panel3.add(URL);
Panel3.add(URLTextField);
Panel3.add(Name);
Panel3.add(NameTextField);
frame.getContentPane().add(Panel1);
frame.getContentPane().add(Panel2);
frame.getContentPane().add(Panel3);
frame.setTitle("Vechicle Details");
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new tryingProject();
}
}