1
我目前正在研究一個我詢問過的程序questions involving previously。CardLayout Manager問題/混淆
從那時起,我已經取得了很大的進步,現在我已經準備好開始在客戶端程序的infoPanel部分。我已經閱讀了文檔和其他問題,但我仍然有點困惑。我如何設置面板,你知道,工作?我如何鏈接它與JList(如果甚至可以使用JList而不是組合框),然後如何確定哪些選擇引用了哪張卡片?
非常感謝您的幫助!
來源:
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class ClientApp extends JFrame
{
public static void main(String[] args)
{
new ClientApp();
}
public ClientApp()
{
this.setSize(320,380);
this.setTitle("Honeydukes Candy Order");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
JPanel infoPanel = new JPanel(new CardLayout());
JPanel invntryPanel = new JPanel();
String[] candy = {"Acid Pops", "Bat's Blood Soup",
"Bertie Bott's Every Flavour Beans",
"Blood-flavoured Lollipops",
"Cauldron Cakes", "Charm Choc",
"Chocoballs", "Chocolate Cauldrons",
"Chocolate Frogs", "Chocolate Skeletons",
"Chocolate Wands", "Choco-Loco", "Cockroach Clusters",
"Nougat", "Crystallised Pineapple",
"Drooble's Best Blowing Gum", "Exploding Bonbons",
"Toffees", "Fizzing Whizzbees",
"Fudge Flies", "Ice Mice",
"Jelly Slugs", "Liquourice Wands",
"Pepper Imps", "Peppermint Toads",
"Pink Coconut Ice", "Pixie Puffs",
"Pumpkin Fizz", "Salt Water Taffy",
"Shock-o-Choc", "Skeletal Sweets",
"Splindle's Lick'O'Rish Spiders",
"Sugar Quills", "Sugared Butterfly Wings",
"Toothflossing Stringmints", "Tooth-Splintering Strongmints",
"Treacle Fudge", "Chocolates", "Wizochoc"};
JList candyList = new JList(candy);
candyList.setVisibleRowCount(18);
candyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scroll = new JScrollPane(candyList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
invntryPanel.add(scroll);
JPanel startCard = new JPanel();
JPanel acidPopsCard = new JPanel();
JPanel batsBloodSoupCard = new JPanel();
JPanel bertieBottsCard = new JPanel();
JPanel bloodPopsCard = new JPanel();
JPanel cauldronCakesCard = new JPanel();
JPanel charmChocCard = new JPanel();
JPanel chocoballsCard = new JPanel();
JPanel chocCauldronsCard = new JPanel();
JPanel chocFrogsCard = new JPanel();
JPanel chocSkeleCard = new JPanel();
JPanel chocWands = new JPanel();
JPanel chocolocoCard = new JPanel();
JPanel roachClustersCard = new JPanel();
JPanel nougatCard = new JPanel();
JPanel crystalPineappleCard = new JPanel();
JPanel droobleGumCard = new JPanel();
JPanel explodeBonbonsCard = new JPanel();
JPanel toffeesCard = new JPanel();
JPanel fizzWhizCard = new JPanel();
JPanel fudgeFliesCard = new JPanel();
JPanel iceMiceCard = new JPanel();
JPanel jellySlugsCard = new JPanel();
JPanel liquorWandsCard = new JPanel();
JPanel pepImpsCard = new JPanel();
JPanel pinkCocoIceCard = new JPanel();
JPanel pixiePuffsCard = new JPanel();
JPanel pumpkFizzCard = new JPanel();
JPanel saltTaffeyCard = new JPanel();
JPanel shockChocCard = new JPanel();
JPanel skeleSweetsCard = new JPanel();
JPanel spindleSpidersCard = new JPanel();
JPanel sugarQuillsCard = new JPanel();
JPanel sugarWingsCard = new JPanel();
JPanel flossMintsCard = new JPanel();
JPanel splintMintsCard = new JPanel();
JPanel treacleFudgeCard = new JPanel();
JPanel chocolatesCard = new JPanel();
JPanel wizochocCard = new JPanel();
infoPanel.add(startCard);
infoPanel.add(acidPopsCard);
infoPanel.add(batsBloodSoupCard);
infoPanel.add(bertieBottsCard);
infoPanel.add(bloodPopsCard);
infoPanel.add(cauldronCakesCard);
infoPanel.add(charmChocCard);
infoPanel.add(chocoballsCard);
infoPanel.add(chocCauldronsCard);
infoPanel.add(chocFrogsCard);
infoPanel.add(chocSkeleCard);
infoPanel.add(chocWands);
infoPanel.add(chocolocoCard);
infoPanel.add(roachClustersCard);
infoPanel.add(nougatCard);
infoPanel.add(crystalPineappleCard);
infoPanel.add(droobleGumCard);
infoPanel.add(explodeBonbonsCard);
infoPanel.add(toffeesCard);
infoPanel.add(fizzWhizCard);
infoPanel.add(fudgeFliesCard);
infoPanel.add(iceMiceCard);
infoPanel.add(jellySlugsCard);
infoPanel.add(liquorWandsCard);
infoPanel.add(pepImpsCard);
infoPanel.add(pinkCocoIceCard);
infoPanel.add(pixiePuffsCard);
infoPanel.add(pumpkFizzCard);
infoPanel.add(saltTaffeyCard);
infoPanel.add(shockChocCard);
infoPanel.add(skeleSweetsCard);
infoPanel.add(spindleSpidersCard);
infoPanel.add(sugarQuillsCard);
infoPanel.add(sugarWingsCard);
infoPanel.add(flossMintsCard);
infoPanel.add(splintMintsCard);
infoPanel.add(treacleFudgeCard);
infoPanel.add(chocolatesCard);
infoPanel.add(wizochocCard);
this.add(invntryPanel, BorderLayout.WEST);
this.add(infoPanel, BorderLayout.EAST);
this.setVisible(true);
}
}
非常感謝您的幫助! – Sam 2012-07-10 00:21:25
@Sam:你很受歡迎! – 2012-07-10 00:22:57