Results 1 to 2 of 2
  1. #1
    Joshidc is offline Member
    Join Date
    Jan 2014
    Location
    Iloilo, Philippines
    Posts
    5
    Rep Power
    0

    Default adding entire code in one button on JFrame

    im trying to put
    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    
    
    
    public class menu {
    	
    	public static void main (String[] args){
    		JFrame frame = new JFrame("Menu");
    		frame.setVisible (true);
    		frame.setSize (400, 320);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		
    		JMenuBar menubar = new JMenuBar();{
    		
    		frame.setJMenuBar (menubar);
    		
    		JMenu FOOD = new JMenu ("FOOD");
    		JMenu BEVERAGES = new JMenu ("BEVERAGES");
    		JMenu DESSERT = new JMenu ("DESSERT");
    		
    		menubar.add(FOOD);
    		menubar.add(BEVERAGES);
    		menubar.add(DESSERT);
    		
    		//Amu ni gina kaon ka mga Dios//
    		
    		JMenu FFTG = new JMenu("Food For The Gods");
    		JMenuItem ZD = new JMenuItem ("Zeus' Delight");
    		JMenuItem HT = new JMenuItem ("Hade's Triumph");
    		JMenuItem PA = new JMenuItem ("Poseidon's Adventure");
    		JMenuItem AO = new JMenuItem ("Apollo's Oracle");
    		JMenuItem HC = new JMenuItem ("Hera's Choice");
    		JMenuItem AR = new JMenuItem ("Aphrodite's Romance");
    		FFTG.add(ZD);
    		FFTG.add(HT);
    		FFTG.add(PA);
    		FFTG.add(AO);
    		FFTG.add(HC);
    		FFTG.add(AR);
    		FOOD.add(FFTG);
    		
    		//Ini sa mga anghel nya naman//
    		
    		JMenu TTRS = new JMenu("Tartarus");
    		JMenuItem DNGN = new JMenuItem ("Dinuguan");
    		JMenuItem BBR = new JMenuItem ("Baby Back Ribs");
    		JMenuItem LK = new JMenuItem ("Lechon Kawali");
    		JMenuItem GC = new JMenuItem ("Gourmet Chicken");
    		JMenuItem CCB = new JMenuItem ("Chicken Cordon Bleu");
    		JMenuItem BS = new JMenuItem ("Beef Stroganoff");
    		JMenuItem BRS = new JMenuItem ("Burger Steak");
    		TTRS.add(DNGN);
    		TTRS.add(BBR);
    		TTRS.add(LK);
    		TTRS.add(GC);
    		TTRS.add(CCB);
    		TTRS.add(BS);
    		TTRS.add(BRS);
    		FOOD.add(TTRS);
    		
    		//pang palaba ni kabuhi//
    		
    		JMenu PD = new JMenu ("Pasta Deliciosa");
    		JMenuItem EPM = new JMenuItem ("Eleos Pancit Molo");
    		JMenuItem SIP = new JMenuItem("Spaghetti Pomodoro");
    		JMenuItem FB = new JMenuItem ("Fideo in Bacon");
    		JMenuItem SP = new JMenuItem ("Seafood Pasta");
    		JMenuItem FTC = new JMenuItem ("Fettucini Tuna Carbonara");
    		PD.add(EPM);
    		PD.add(SIP);
    		PD.add(FB);
    		PD.add(SP);
    		PD.add(FTC);
    		FOOD.add(PD);
    		
    		//edible hilamon//
    		
    		JMenu OG = new JMenu ("Olympus' Garden");
    		JMenuItem FP = new JMenuItem ("Fresh Platter");
    		JMenuItem PM = new JMenuItem ("Potato Marbles");
    		JMenuItem FC = new JMenuItem ("Florets in Cream");
    		JMenuItem CW = new JMenuItem ("Coleslaw");
    		JMenuItem EP = new JMenuItem ("Eddieble's Pride");
    		OG.add(FP);
    		OG.add(PM);
    		OG.add(FC);
    		OG.add(CW);
    		OG.add(EP);
    		FOOD.add(OG);
    		
    		//BEVERAGES//
    		JMenu BVS = new JMenu ("BEVERAGES");
    		JMenuItem J = new JMenuItem ("Joe");
    		JMenuItem C8 = new JMenuItem ("Coke 8oz");
    		JMenuItem C12 = new JMenuItem ("Coke 12oz");
    		JMenuItem CC = new JMenuItem ("Coke in Can");
    		JMenuItem S8 = new JMenuItem ("Sprite 8oz");
    		JMenuItem S12 = new JMenuItem ("Sprite 12 oz");
    		JMenuItem SC = new	JMenuItem ("Sprite in Can");
    		JMenuItem R8 = new JMenuItem ("Royal 8oz");
    		JMenuItem R12 = new JMenuItem("Royal 12oz");
    		JMenuItem RC = new JMenuItem ("Royal in Can");
    		JMenuItem BW3 = new JMenuItem ("Bottled Water 350ml");
    		JMenuItem BW5 = new JMenuItem ("Bottled Water 500ml");
    		BVS.add(J);
    		BVS.add(C8);
    		BVS.add(C12);
    		BVS.add(CC);
    		BVS.add(S8);
    		BVS.add(S12);
    		BVS.add(SC);
    		BVS.add(R8);
    		BVS.add(R12);
    		BVS.add(RC);
    		BVS.add(BW3);
    		BVS.add(BW5);
    		BEVERAGES.add (BVS);
    		
    		//DESSERT//
    		JMenu CS = new JMenu ("Cakes");
    		JMenuItem CD = new JMenuItem ("Chocoholic's Dream");
    		JMenuItem CTC = new JMenuItem ("Carrot Cake");
    		JMenuItem BBCC = new JMenuItem ("Blueberry Cheesecake");
    		JMenuItem SBCC = new JMenuItem ("Strawberry Cheesecake");
    		JMenuItem TU = new JMenuItem ("Tiramisu");
    		JMenuItem SPC =  new JMenuItem ("Sponge Cake");
    		JMenuItem LF = new JMenuItem ("Leche Flan");
    		CS.add(CD);
    		CS.add(CTC);
    		CS.add(BBCC);
    		CS.add(SBCC);
    		CS.add(TU);
    		CS.add(SPC);
    		CS.add(LF);
    		DESSERT.add (CS);
    
    		JMenu PS = new JMenu ("Pies");
    		JMenuItem ASP = new JMenuItem ("Apple Streusel Pie");
    		JMenuItem BP = new JMenuItem ("Buco Pie");
    		JMenuItem WP = new JMenuItem ("Walnut Pie");
    		JMenuItem PP = new JMenuItem ("Pineapple Pie");
    		JMenuItem CSP = new JMenuItem ("Custard Snow Pie");
    		PS.add(ASP);
    		PS.add(BP);
    		PS.add(WP);
    		PS.add(PP);
    		PS.add(CSP);
    		DESSERT.add (PS);
    		
    		JMenu PST = new JMenu ("Pastries");
    		JMenuItem FFG = new JMenuItem ("Food For The Gods");
    		JMenuItem EM = new JMenuItem ("Empanaditas");
    		JMenuItem BTS = new JMenuItem ("Butter Scotch");
    		JMenuItem PN = new JMenuItem ("Pulvoron");
    		JMenuItem CCS = new JMenuItem ("Chocolate Crinkles");
    		JMenuItem BQS = new JMenuItem ("Barquillos");
    		JMenuItem EMP = new JMenuItem ("Empanadas");
    		JMenuItem FL = new JMenuItem ("Fresh Lumpia");
    		JMenuItem BC = new JMenuItem ("Banana Chips");
    		JMenuItem FCR = new JMenuItem ("Fruit Cake Roons");
    		JMenuItem FCB = new JMenuItem ("Fruit Cake Bars");
    		PST.add(FFG);
    		PST.add(EM);
    		PST.add(BTS);
    		PST.add(PN);
    		PST.add(CCS);
    		PST.add(BQS);
    		PST.add(EMP);
    		PST.add(FL);
    		PST.add(BC);
    		PST.add(FCR);
    		PST.add(FCB);
    		DESSERT.add (PST);
    		}
    	}
    }
    inside button 1 of EMB1
    Java Code:
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.Box;
    import javax.swing.JButton;
    import javax.swing.BoxLayout;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class EM extends JFrame
    
    
    
    {
    
        public EM () 
        	{
        		super ("WELCOME TO ELIOS");
    
    	Box EMB1 = Box.createVerticalBox();
    	Box EMB2 = Box.createVerticalBox();
    	Box EMB3 = Box.createHorizontalBox();
    	Box EMB4 = Box.createHorizontalBox();
    	Box EMB5 = Box.createHorizontalBox();
    	Box EMB6 = Box.createHorizontalBox();
    	Box EMB7 = Box.createHorizontalBox();
    	Box EMB8 = Box.createHorizontalBox();
    	Box EMB9 = Box.createHorizontalBox();
    	Box EMB10 = Box.createHorizontalBox();
    	Box EMB11 = Box.createHorizontalBox();
    	Box EMB12 = Box.createHorizontalBox();
    	
    	
    		EMB1.add( Box.createVerticalBox());
    		EMB1.add(new JButton("1"));
    
    	
    		EMB2.add( Box.createVerticalBox());
    		EMB2.add(new JButton("1"));
    	
    						
    		
    	
    		
    		
    		JTabbedPane tabs = new JTabbedPane(
    		JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    and i ended up with
    Java Code:
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.Box;
    import javax.swing.JButton;
    import javax.swing.BoxLayout;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class EM extends JFrame
    
    
    
    {
    
        public EM () 
        	{
        		super ("WELCOME TO ELIOS");
    
    	Box EMB1 = Box.createVerticalBox();
    	Box EMB2 = Box.createVerticalBox();
    	Box EMB3 = Box.createHorizontalBox();
    	Box EMB4 = Box.createHorizontalBox();
    	Box EMB5 = Box.createHorizontalBox();
    	Box EMB6 = Box.createHorizontalBox();
    	Box EMB7 = Box.createHorizontalBox();
    	Box EMB8 = Box.createHorizontalBox();
    	Box EMB9 = Box.createHorizontalBox();
    	Box EMB10 = Box.createHorizontalBox();
    	Box EMB11 = Box.createHorizontalBox();
    	Box EMB12 = Box.createHorizontalBox();
    	
    	
    	{
    		EMB1.add( Box.createVerticalBox());
    		EMB1.add(new JButton("1"));
    		{
    			
    class menu {
    	
    	public void main (String[] args){
    		JFrame frame = new JFrame("Menu");
    		frame.setVisible (true);
    		frame.setSize (400, 320);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		
    		JMenuBar menubar = new JMenuBar();{
    		
    		frame.setJMenuBar (menubar);
    		
    		JMenu FOOD = new JMenu ("FOOD");
    		JMenu BEVERAGES = new JMenu ("BEVERAGES");
    		JMenu DESSERT = new JMenu ("DESSERT");
    		
    		menubar.add(FOOD);
    		menubar.add(BEVERAGES);
    		menubar.add(DESSERT);
    		
    		//Amu ni gina kaon ka mga Dios//
    		
    		JMenu FFTG = new JMenu("Food For The Gods");
    		JMenuItem ZD = new JMenuItem ("Zeus' Delight");
    		JMenuItem HT = new JMenuItem ("Hade's Triumph");
    		JMenuItem PA = new JMenuItem ("Poseidon's Adventure");
    		JMenuItem AO = new JMenuItem ("Apollo's Oracle");
    		JMenuItem HC = new JMenuItem ("Hera's Choice");
    		JMenuItem AR = new JMenuItem ("Aphrodite's Romance");
    		FFTG.add(ZD);
    		FFTG.add(HT);
    		FFTG.add(PA);
    		FFTG.add(AO);
    		FFTG.add(HC);
    		FFTG.add(AR);
    		FOOD.add(FFTG);
    		
    		//Ini sa mga anghel nya naman//
    		
    		JMenu TTRS = new JMenu("Tartarus");
    		JMenuItem DNGN = new JMenuItem ("Dinuguan");
    		JMenuItem BBR = new JMenuItem ("Baby Back Ribs");
    		JMenuItem LK = new JMenuItem ("Lechon Kawali");
    		JMenuItem GC = new JMenuItem ("Gourmet Chicken");
    		JMenuItem CCB = new JMenuItem ("Chicken Cordon Bleu");
    		JMenuItem BS = new JMenuItem ("Beef Stroganoff");
    		JMenuItem BRS = new JMenuItem ("Burger Steak");
    		TTRS.add(DNGN);
    		TTRS.add(BBR);
    		TTRS.add(LK);
    		TTRS.add(GC);
    		TTRS.add(CCB);
    		TTRS.add(BS);
    		TTRS.add(BRS);
    		FOOD.add(TTRS);
    		
    		//pang palaba ni kabuhi//
    		
    		JMenu PD = new JMenu ("Pasta Deliciosa");
    		JMenuItem EPM = new JMenuItem ("Eleos Pancit Molo");
    		JMenuItem SIP = new JMenuItem("Spaghetti Pomodoro");
    		JMenuItem FB = new JMenuItem ("Fideo in Bacon");
    		JMenuItem SP = new JMenuItem ("Seafood Pasta");
    		JMenuItem FTC = new JMenuItem ("Fettucini Tuna Carbonara");
    		PD.add(EPM);
    		PD.add(SIP);
    		PD.add(FB);
    		PD.add(SP);
    		PD.add(FTC);
    		FOOD.add(PD);
    		
    		//edible hilamon//
    		
    		JMenu OG = new JMenu ("Olympus' Garden");
    		JMenuItem FP = new JMenuItem ("Fresh Platter");
    		JMenuItem PM = new JMenuItem ("Potato Marbles");
    		JMenuItem FC = new JMenuItem ("Florets in Cream");
    		JMenuItem CW = new JMenuItem ("Coleslaw");
    		JMenuItem EP = new JMenuItem ("Eddieble's Pride");
    		OG.add(FP);
    		OG.add(PM);
    		OG.add(FC);
    		OG.add(CW);
    		OG.add(EP);
    		FOOD.add(OG);
    		
    		//BEVERAGES//
    		JMenu BVS = new JMenu ("BEVERAGES");
    		JMenuItem J = new JMenuItem ("Joe");
    		JMenuItem C8 = new JMenuItem ("Coke 8oz");
    		JMenuItem C12 = new JMenuItem ("Coke 12oz");
    		JMenuItem CC = new JMenuItem ("Coke in Can");
    		JMenuItem S8 = new JMenuItem ("Sprite 8oz");
    		JMenuItem S12 = new JMenuItem ("Sprite 12 oz");
    		JMenuItem SC = new	JMenuItem ("Sprite in Can");
    		JMenuItem R8 = new JMenuItem ("Royal 8oz");
    		JMenuItem R12 = new JMenuItem("Royal 12oz");
    		JMenuItem RC = new JMenuItem ("Royal in Can");
    		JMenuItem BW3 = new JMenuItem ("Bottled Water 350ml");
    		JMenuItem BW5 = new JMenuItem ("Bottled Water 500ml");
    		BVS.add(J);
    		BVS.add(C8);
    		BVS.add(C12);
    		BVS.add(CC);
    		BVS.add(S8);
    		BVS.add(S12);
    		BVS.add(SC);
    		BVS.add(R8);
    		BVS.add(R12);
    		BVS.add(RC);
    		BVS.add(BW3);
    		BVS.add(BW5);
    		BEVERAGES.add (BVS);
    		
    		//DESSERT//
    		JMenu CS = new JMenu ("Cakes");
    		JMenuItem CD = new JMenuItem ("Chocoholic's Dream");
    		JMenuItem CTC = new JMenuItem ("Carrot Cake");
    		JMenuItem BBCC = new JMenuItem ("Blueberry Cheesecake");
    		JMenuItem SBCC = new JMenuItem ("Strawberry Cheesecake");
    		JMenuItem TU = new JMenuItem ("Tiramisu");
    		JMenuItem SPC =  new JMenuItem ("Sponge Cake");
    		JMenuItem LF = new JMenuItem ("Leche Flan");
    		CS.add(CD);
    		CS.add(CTC);
    		CS.add(BBCC);
    		CS.add(SBCC);
    		CS.add(TU);
    		CS.add(SPC);
    		CS.add(LF);
    		DESSERT.add (CS);
    
    		JMenu PS = new JMenu ("Pies");
    		JMenuItem ASP = new JMenuItem ("Apple Streusel Pie");
    		JMenuItem BP = new JMenuItem ("Buco Pie");
    		JMenuItem WP = new JMenuItem ("Walnut Pie");
    		JMenuItem PP = new JMenuItem ("Pineapple Pie");
    		JMenuItem CSP = new JMenuItem ("Custard Snow Pie");
    		PS.add(ASP);
    		PS.add(BP);
    		PS.add(WP);
    		PS.add(PP);
    		PS.add(CSP);
    		DESSERT.add (PS);
    		
    		JMenu PST = new JMenu ("Pastries");
    		JMenuItem FFG = new JMenuItem ("Food For The Gods");
    		JMenuItem EM = new JMenuItem ("Empanaditas");
    		JMenuItem BTS = new JMenuItem ("Butter Scotch");
    		JMenuItem PN = new JMenuItem ("Pulvoron");
    		JMenuItem CCS = new JMenuItem ("Chocolate Crinkles");
    		JMenuItem BQS = new JMenuItem ("Barquillos");
    		JMenuItem EMP = new JMenuItem ("Empanadas");
    		JMenuItem FL = new JMenuItem ("Fresh Lumpia");
    		JMenuItem BC = new JMenuItem ("Banana Chips");
    		JMenuItem FCR = new JMenuItem ("Fruit Cake Roons");
    		JMenuItem FCB = new JMenuItem ("Fruit Cake Bars");
    		PST.add(FFG);
    		PST.add(EM);
    		PST.add(BTS);
    		PST.add(PN);
    		PST.add(CCS);
    		PST.add(BQS);
    		PST.add(EMP);
    		PST.add(FL);
    		PST.add(BC);
    		PST.add(FCR);
    		PST.add(FCB);
    		DESSERT.add (PST);
    		}
    	}
    }
    
    		}	
    		
    		
    	}
    		EMB2.add( Box.createVerticalBox());
    		EMB2.add(new JButton("1"));
    	
    						
    		
    	
    		
    		
    		JTabbedPane tabs = new JTabbedPane(
    		JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    		
    	
    	tabs.addTab("TABLE 1", EMB1);
    	tabs.addTab("TABLE 2", EMB2);
    	tabs.addTab("TABLE 3", EMB3);
    	tabs.addTab("TABLE 4", EMB4);
    	tabs.addTab("TABLE 5", EMB5);
    	tabs.addTab("TABLE 6", EMB6);
    	tabs.addTab("TABLE 7", EMB7);
    	tabs.addTab("TABLE 8", EMB8);
    	tabs.addTab("TABLE 9", EMB9);
    	tabs.addTab("TABLE 10", EMB10);
    	tabs.addTab("TABLE 11", EMB11);
    	tabs.addTab("TABLE 12", EMB12);
    
    
    	
    	
    	add(tabs);	
        }
    }
    but it doesnt show when i click the button when i run
    Java Code:
    import javax.swing.JFrame;
    
    public class EMP
    {
    	public static void main (String[] args) 
    		{
    			EM em = new EM();
    			em.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    			em.setSize(860,600);
    			em.setVisible(true);
        }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default Re: adding entire code in one button on JFrame

    Does this code compile? You have a bunch of extra curly braces, and I'm really not sure what your question is.

    Instead of posting your full code, why don't you post an SSCCE that consists of a single JButton that does just ONE thing, not 100 different things?

    Edit- Also, please don't post multiple copies of the same question. I've deleted your duplicate post.
    Last edited by KevinWorkman; 01-30-2014 at 03:13 PM.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 17
    Last Post: 07-25-2013, 04:43 AM
  2. Replies: 0
    Last Post: 05-24-2011, 07:50 AM
  3. Adding a sqrt button and percentage button to a calculator
    By Josie_Taylor in forum New To Java
    Replies: 4
    Last Post: 03-14-2011, 01:16 AM
  4. adding entire inventory in array?
    By extremeshannon in forum Java Applets
    Replies: 2
    Last Post: 07-29-2010, 12:03 AM
  5. Repaint the entire JFrame (GroupLayout)
    By Willi in forum AWT / Swing
    Replies: 13
    Last Post: 12-19-2009, 10:11 PM

Tags for this Thread

Posting Permissions

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