1
我創建了一個類名爲框架簡單地創建一個框架創建的框架:如何JPanel中添加
package panels;
public class Frame extends prog
{
public Frame() {
JFrame myFrame = new JFrame();
myFrame.setLayout(new FlowLayout());
myFrame.setTitle("GUI Demo - ISTE-121");
myFrame.pack();
myFrame.setLocation(600,300);
myFrame.setSize(400,200);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setVisible(true);
}
}
然後,我已經加入該幀的main()
:
package panels;
public class prog {
public static void main(String args[]) {
Frame first = new Frame();
}
}
我已經創建了一個名爲面板的類,並且希望將其添加到類框架中。我應該怎麼做?
子類如下:您的第一個類的
public class panels extends Frame {
final JTextField items;
final JTextField number;
final JTextField cost;
final JTextField amount;
public panels()
{
JPanel order = new JPanel();
order.setLayout(new GridLayout(5,5,2,2));
order.add(new JLabel("Item no:", SwingConstants.RIGHT));
order.add(items = new JTextField(3));
order.add(new JLabel("Number of:", SwingConstants.RIGHT));
order.add(number = new JTextField(3));
order.add(new JLabel("Cost", SwingConstants.RIGHT));
order.add(cost = new JTextField(3));
order.add(new JLabel("Amount owed:", SwingConstants.RIGHT));
order.add(amount = new JTextField(10));
amount.setEditable(false);
}
}
爲什麼這個類擴展'Frame'?你想補充什麼?那就是,你想要發生什麼? – RealSkeptic 2015-02-10 10:21:09