我正在嘗試製作一個銷售糕點,百吉餅和咖啡的當地百吉餅店的計劃。我無法實現我所做成的JFrameJFrame和JPanel問題
任何瞭解如何使我的JFrame看起來像這將是有益的幫助下,面板http://kepler.covenant.edu/COS150/Bagel_files/image002.jpg
一旦我有這個工作,我希望能有中間套面板會根據所選產品而變化。我不完全確定如何使按鈕和麪板互相交談。
感謝您的幫助!
這是我迄今爲止的JFrame代碼。
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class BagelOrder extends JFrame
{
JLabel topLabel;
sizePanel sp = new sizePanel();
typePanel tp = new typePanel();
productsPanel pp = new productsPanel();
buttonPanel bp = new buttonPanel();
extrasPanel ep = new extrasPanel();
public BagelOrder()
{
setTitle("Order Entry Screen");
setSize(800, 800);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
topLabel = new JLabel("Order Entry Screen");
add(pp, BorderLayout.WEST);
add(topLabel, BorderLayout.NORTH);
add(bp, BorderLayout.SOUTH);
add(middleCoffeePanelSetBuild(), BorderLayout.CENTER);
add(east, BorderLayout.EAST);
setVisible(true);
}
private JPanel middleCoffeePanelSetBuild()
{
JPanel middlePanel = new JPanel(new GridLayout(3,1));
add(sp);
add(tp);
add(ep);
}
public static void main(String args[])
{
BagelOrder bo = new BagelOrder();
}
}
我沒有任何錯誤,但除了頁面頂部的標籤之外我什麼都看不到。
,這裏是我的其他類
代碼ButtonPanel
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JPanel;
public class buttonPanel extends JPanel
{
JButton enterItemButton;
JPanel buttonPanel;
ButtonGroup bg;
JButton totalButton;
JButton newOrderButton;
public buttonPanel()
{
buttonPanel = new JPanel(new GridLayout(1,3));
bg = new ButtonGroup();
enterItemButton = new JButton("Enter Item");
totalButton = new JButton("Total");
newOrderButton = new JButton("New Order");
buttonPanel.setSize(150, 780);
buttonPanel.add(enterItemButton);
bg.add(enterItemButton);
buttonPanel.add(totalButton);
bg.add(totalButton);
buttonPanel.add(newOrderButton);
bg.add(newOrderButton);
setVisible(true);
}
}
ProductPanel
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;
public class productsPanel extends JPanel
{
public productsPanel()
{
JPanel productPanel = new JPanel(new GridLayout(3,1));
ButtonGroup bg = new ButtonGroup();
JRadioButton coffeeButton = new JRadioButton("Coffee");
JRadioButton bagelButton = new JRadioButton("Bagel");
JRadioButton pastryButton = new JRadioButton("Pastry");
productPanel.setSize(150, 780);
productPanel.add(coffeeButton);
bg.add(coffeeButton);
productPanel.add(bagelButton);
bg.add(bagelButton);
productPanel.add(pastryButton);
bg.add(pastryButton);
Border etched = BorderFactory.createEtchedBorder();
Border titled = BorderFactory.createTitledBorder(etched, "Products");
productPanel.setBorder(titled);
setVisible(true);
}
}
尺寸面板
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;
public class sizePanel extends JPanel{
public sizePanel()
{
JPanel sp = new JPanel(new GridLayout(3,1));
ButtonGroup bg = new ButtonGroup();
JRadioButton smallButton = new JRadioButton("Small");
JRadioButton mediumButton = new JRadioButton("Medium");
JRadioButton largeButton = new JRadioButton("Large");
sp.setSize(200, 200);
sp.add(smallButton);
bg.add(smallButton);
sp.add(mediumButton);
bg.add(mediumButton);
sp.add(largeButton);
bg.add(largeButton);
Border etched = BorderFactory.createEtchedBorder();
Border titled = BorderFactory.createTitledBorder(etched, "Size");
sp.setBorder(titled);
setVisible(true);
}
}
TypePanel
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;
public class typePanel extends JPanel
{
public typePanel()
{
JPanel typePanel = new JPanel(new GridLayout(3,1));
ButtonGroup bg = new ButtonGroup();
JRadioButton regularButton = new JRadioButton("Regular");
JRadioButton decafButton = new JRadioButton("Decaf");
JRadioButton frenchRoastButton = new JRadioButton("French Roast");
typePanel.setSize(200, 200);
typePanel.add(regularButton);
bg.add(regularButton);
typePanel.add(decafButton);
bg.add(decafButton);
typePanel.add(frenchRoastButton);
bg.add(frenchRoastButton);
Border etched = BorderFactory.createEtchedBorder();
Border titled = BorderFactory.createTitledBorder(etched, "Type");
typePanel.setBorder(titled);
setVisible(true);
}
}
ExtrasPanel
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.border.Border;
public class extrasPanel extends JPanel
{
public extrasPanel()
{
JPanel extrasPanel = new JPanel(new GridLayout(2,1));
JCheckBox creamCheckBox = new JCheckBox("Cream");
JCheckBox sugarCheckBox = new JCheckBox("Sugar");
extrasPanel.setSize(200, 200);
extrasPanel.add(creamCheckBox);
extrasPanel.add(sugarCheckBox);
Border etched = BorderFactory.createEtchedBorder();
Border titled = BorderFactory.createTitledBorder(etched, "Extras");
extrasPanel.setBorder(titled);
setVisible(true);
}
}