Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Fubarable

Thread: MessageDialogBox help

  1. #1
    aleale91 is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Exclamation MessageDialogBox help

    Hello everyone :) I'm working on a project for collage, something like an order in a restaurant, and I don't know how to do it... Well, the thing is, I want when I click "Narudžba" (order) to show a messagedialogbox saying all the things I selected (RadioButton, ComboBox, CheckBox...), but everything in a new row so it would look something like this:




    Here's how the form looks:



    Cena button should show in the textbox how much is the order, but I didn't get to that part...

    Here's the code for my project:

    Java Code:
    import java.awt.*;
    import java.applet.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    
    
    public class Hamburgerija {
    
    public static JRadioButton hamb, čiz, pljes, ćev, pizza;
    public static JComboBox k;
    
    public static void main(String[] args) {
    
        	JFrame frame = new JFrame("Hamburgerija");
        		frame.setVisible(true);
        		frame.setSize(600,400);
        		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    		JPanel panel = new JPanel();
    			panel.setLayout(new GridLayout(11, 3, 1, 2));
    			panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    
    		//KOMANDE //
    		JLabel lblprazno11 = new JLabel(""); //empty label
    			panel.add(lblprazno11);
    
    		JLabel lblNaslov = new JLabel("        NARUDŽBA"); //2
    			lblNaslov.setFont(new Font("Tahoma", 1, 20));
    			panel.add(lblNaslov);
    
    		JButton cmdNaruci = new JButton("Naruči"); //3
    			panel.add(cmdNaruci);
    
    		JLabel lblpraznop = new JLabel("");
    			panel.add(lblpraznop);
    
    		JLabel lblprazno91 = new JLabel("");
    			panel.add(lblprazno91);
    
    		JLabel lblprazno6 = new JLabel("");
    			panel.add(lblprazno6);
    
    		JLabel lblObrok = new JLabel("     Obrok:"); //7
    			lblObrok.setFont(new Font("Tahoma",1, 15));
    			panel.add(lblObrok);
    
    		JLabel lblprazno28 = new JLabel("");
    			panel.add(lblprazno28);
    
    		JLabel lblKoličina = new JLabel("     Količina:"); //9
    			lblKoličina.setFont(new Font("Tahoma",1, 15));
    			panel.add(lblKoličina);
    
    		ButtonGroup grupa = new ButtonGroup();
    			hamb = new JRadioButton("# 1 Hamburger (110 din)");
    			čiz = new JRadioButton("# 2 Čizburger (120 din)");
    			pljes = new JRadioButton("# 3 Pljeskavica (140 din)");
    			ćev = new JRadioButton("# 4 Pet ćevapa (135 din)");
    			pizza = new JRadioButton("# 5 Pizza (120 din)");
    
    			grupa.add(hamb);
    			grupa.add(čiz);
    			grupa.add(pljes);
    			grupa.add(ćev);
    			grupa.add(pizza);
    
    		panel.add(hamb); //10
    		JLabel lblprazno121 = new JLabel("");
    			panel.add(lblprazno121);
    
    		k = new JComboBox();
    			k.addItem("1");
    			k.addItem("2");
    			k.addItem("3");
    			k.addItem("4");
    			k.addItem("5");
    			panel.add(k);
    
    		panel.add(čiz); //13
    		JLabel lblprazno22 = new JLabel("");
    			panel.add(lblprazno22);
    
    		JLabel lblprazno15 = new JLabel("");
    		        panel.add(lblprazno15);
    
    		panel.add(pljes);//16
    		JLabel lblprazno32 = new JLabel("");
    			panel.add(lblprazno32);
    
    		JCheckBox extra = new JCheckBox("Ekstra količina? +20%");
    			panel.add(extra);
    
    		panel.add(ćev);//19
    		JLabel lblprazno42 = new JLabel("");
    			panel.add(lblprazno42);
    
    		JCheckBox senior = new JCheckBox("Senior? -10%");
    			panel.add(senior);
    
    		panel.add(pizza);//22
    		JLabel lblprazno52 = new JLabel("");
    			panel.add(lblprazno52);
    
    		JLabel lblpraznob = new JLabel("");
    			panel.add(lblpraznob);
    
    		JLabel lblprazno82 = new JLabel("");
    			panel.add(lblprazno82);
    
    		JLabel lblprazno26 = new JLabel("");
    			panel.add(lblprazno26);
    
    		JLabel lblprazno277 = new JLabel("");
    			panel.add(lblprazno277);
    
    		JButton cmdCena = new JButton("Cena"); //19
    			panel.add(cmdCena);
    
    		JTextField txtcena = new JTextField();
    				panel.add(txtcena);
    
    		JLabel lblprazno27 = new JLabel("");
    			panel.add(lblprazno27);
    
    		JLabel lblpraznoc = new JLabel("");
    			panel.add(lblpraznoc);
    
    frame.add(panel);
     }
    }
    Again, I want a message box to appear when I click on button Narudžba saying all the things I selected. I hope someone will help...

  2. #2
    k1ng is offline Member
    Join Date
    Apr 2012
    Posts
    59
    Rep Power
    0

    Default Re: MessageDialogBox help

    You first need to tell your program to watch cmdCena for a click action by using an event listener. Then in the event execution code block you need to simply add everything that's selected to a string and print it to a JOptionPane.showXXXDialog

  3. #3
    aleale91 is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: MessageDialogBox help

    You mean cmdNaruci? Because that's the button I want to click so that it shows what I've selected... But nevermind, I understand what I should do, but I don't know how to do it :) I'm new to java, so if you could type a code, it would be very appreciated.

  4. #4
    aleale91 is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: MessageDialogBox help

    Anyone?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •