这是“主”类(不包含的主要方法)不同的窗口具有相同的代码?
import javax.swing.*;
import java.awt.*;
//import java.lang.Object;
//import java.awt.event.ActionListener;
//import java.awt.event.;
public class Program {
public JFrame frame;
public JPanel header;
public JPanel text;
public JPanel body;
public JTextField input;
public JButton agregar;
public List listA;
public List listB;
public Program(String title) {
frame = new JFrame(title);
frame.setSize(500,600);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
header = new JPanel();
header.setBackground(new Color(255,204,50));
header.setBounds(0,0,500,100);
text = new JPanel();
text.setBackground(new Color(255,204,100));
text.setBounds(0,100,500,50);
text.setLayout(null);
//Inicializando la "entrada"
input = new JTextField(20);
input.setBounds(50,13,300,25);
text.add(input);
agregar = new JButton();
agregar.setBounds(360,12,80,25);
agregar.setText("Agregar");
text.add(agregar);
//Listo
body = new JPanel();
body.setBackground(new Color(255,204,150));
body.setBounds(0,150,500,450);
//Lo que está dentro del body
listA = new List(20);
body.add(listA);
listB = new List(20);
body.add(listB);
//Listo
//Añadir todos los paneles al frame principal
frame.add(header);
frame.add(text);
frame.add(body);
}
}
这是主类(这其中包含的主要方法):
public class Main {
public static void main(String[] args) {
new Program("Ordenamiento Recursivo");
}
}
每次我运行应用程序,UI组件呈现不同,请参阅附加的屏幕截图。
好,感谢大家谁回答后,我完成了计划,我很高兴与最终的结果,那就是:
如果有人想看看代码,这里是:Link
这里是发生了什么事情的PIC:https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash3/s720x720/542011_351231484935185_100001450101764_1038411_1654559456_n.jpg – hinafu 2012-04-27 15:43:40
什么问题?每次你运行它你会得到新的窗口?当然,你会开始一个新的过程。 – BeRecursive 2012-04-27 15:44:52
你可能会尝试在你的问题中加一点__更多的努力(尽管英语不好) - 很难弄清楚你得到了什么,你期望什么,从而可能会出错。你有没有尝试和调试你的应用程序? – Thomas 2012-04-27 15:44:56