Results 1 to 2 of 2
- 11-10-2012, 04:32 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
How to put an input dialog box in a combo box program
I'm making this program that's supposed to act as a menu for specials at a cafe. What I'd like to happen is, when the program is run and the user is done looking through the specials in the combo box and they close it, an input dialog box appears asking which item they picked. I just don't know how to put an input dialog box in.
I'm very new to Java, and I copied the combo box code from my Java programming book (which is why you see the word "flag" everywhere - the code was originally meant to show flags and their descriptions). I need to make all kinds of programs for a project in my software technology class, which is why I chose a program that I don't fully understand yet. But I just need to figure out how to put an input dialog in. Someone on dreamincode.net told me this..
So.. what kind of resources can I look up that will help me understand how to do this? Or, better yet, can one of you guys help me understand?GUI applications are event driven...
you display some components an depending the way user interact with them you react to them
JOptionPane is not such a component. The display of a JOptionPane should be triggered by a JButton, or another situation. You cannot display a JOptionPane in the normal GUI bulding process.
Here's my code:
Java Code:mport java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Scanner; public class ComboBoxDemo extends JFrame { private double order = 0; // Declare an array of Strings for flag titles private String[] flagTitles = {"The Big Easy", "The Sophisticated Ensemble", "The Delectable"}; // Declare an ImageIcon array for the national flags of 9 countries private ImageIcon[] flagImage = { new ImageIcon("Images/bigeasy.jpg"), new ImageIcon("Images/sophisticatedensemble.jpg"), new ImageIcon("Images/thedelectable.jpg"), }; // Declare an array of strings for flag descriptions private String[] flagDescription = new String[3]; // Declare and create a description panel private JTextPane Description = new JTextPane(); private JLabel flagImageLabel = new JLabel(); private JComboBox jcbo = new JComboBox(flagTitles); // Create a combo box for selecting countries public static void main(String[] args) { ComboBoxDemo frame = new ComboBoxDemo(); frame.pack(); frame.setTitle("Modern Papyrus Cafe Menu"); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public ComboBoxDemo() { // Set text description flagDescription[0] = "1: The Big Easy is, simply put, a big and easy meal!\n" + "It consists of 1 hearty sandwich, stuffed with anything you want\n" + "1 bag of crunchy and savory chips, of your choice\n" + "and 1 large drink, all for $10.99!\n" + "And we've got better news: you can also include any book you choose for 25% off,\n" + "just for buying this meal!"; flagDescription[1] = "2: The Sophisticated Ensemble is for those that want to\n" + "take delight in a warmer, sit-by-the-fire kind of meal. It contains:\n " + "1 pastry, donut, brownie, or slice of cake\n" + "and 1 coffee, latte, or tea, all for $8.99!\n" + "To finalize the deal, you may add a book to your purchase for 15% off!"; flagDescription[2] = "3: The Delectable is for the sweet tooth! You may have\n" + "1 milkshake, smoothie, or hot chocolate\n" + "and 1 pastry, donut, brownie, or slice of cake, all for $7.99!\n" + "To sweeten the deal, you may add a book to your purchase for 15% off!"; // Set the first country (Canada) for display setDisplay(0); Description.setText(flagDescription[0]); flagImageLabel.setIcon(flagImage[0]); Description.setPreferredSize(new Dimension(400,300)); flagImageLabel.setPreferredSize(new Dimension(300,200)); // Add combo box and description panel to the list add(jcbo, BorderLayout.NORTH); add(Description, BorderLayout.CENTER); add(flagImageLabel, BorderLayout.WEST); // Register listener jcbo.addItemListener(new ItemListener() { /** Handle item selection */ public void itemStateChanged(ItemEvent e) { Description.setText(flagDescription[jcbo.getSelectedIndex()]); flagImageLabel.setIcon(flagImage[jcbo.getSelectedIndex()]); } }); } /** Set display information on the description panel */ public void setDisplay(int index) { } }
- 11-13-2012, 05:41 PM #2
Re: How to put an input dialog box in a combo box program
Sure you can. JOptionPane (Java Platform SE 6)You cannot display a JOptionPane in the normal GUI bulding process.
Look at the showInputDialog() method and some of the others. You can pop up an JOptionPane any time!
Similar Threads
-
Validate editable combo box input as integer and not empty
By Rogue45 in forum AWT / SwingReplies: 4Last Post: 04-28-2012, 12:13 AM -
Help with Int and JOption Input dialog
By stephanie904 in forum New To JavaReplies: 1Last Post: 02-29-2012, 01:22 AM -
How to create custom Input Dialog
By Bab in forum SWT / JFaceReplies: 2Last Post: 08-02-2009, 12:21 PM -
JOptionPane - input dialog
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 09:09 AM -
Multiple Line Input Dialog Box
By johnt in forum AWT / SwingReplies: 2Last Post: 05-31-2007, 09:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks