473,498 Members | 1,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorry bug you guys but can somebody help me?

18 New Member
I created buttons in the menu,no syntax error but cardholder is not visible. Please help!!!


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import javax.swing.table.*;
  4. import java.awt.event.*;
  5.  
  6. public class MainMenu extends JFrame implements ActionListener
  7. {
  8.     private DefaultTableModel model;
  9.     private JTable table;
  10.     private JScrollPane scroll;
  11.     private JPanel panel;
  12.  
  13.     private CardLayout cardLayout;
  14.     private JPanel cardHolder;
  15.  
  16.     private GridBagLayout gridBag;
  17.     private GridBagConstraints c;
  18.  
  19.     static JPanel mainMenuCard, manageCustomerCard,manageSaleCard,manageSaleBookCard,makeOrderCard,viewCartCard;
  20.     static JLabel titleLbl;
  21.     static JButton manageCustomerBtn,manageSaleBtn,manageSaleBookBtn,makeOrderBtn,viewCartBtn,exitBtn;
  22.  
  23.  
  24.     public MainMenu()
  25.     {
  26.         super("MainMenu");
  27.         setSize(800,800);
  28.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29.         createGUI();
  30.         setVisible(true);
  31.  
  32.         cardLayout = new CardLayout();
  33.         cardHolder = new JPanel();
  34.         cardHolder.setLayout(cardLayout);
  35.  
  36.         //createMainMenuCard();
  37.         titleLbl=new JLabel("MAIN MENU");
  38.         manageCustomerBtn=new JButton("Manage Customer");
  39.         manageSaleBtn=new JButton("Manage Sale");
  40.         manageSaleBookBtn=new JButton("Manage Sale Book");
  41.         makeOrderBtn=new JButton("Make Order");
  42.         viewCartBtn=new JButton("View Cart");
  43.         exitBtn=new JButton("Exit");
  44.  
  45.         cardHolder.add(mainMenuCard,"mainMenuCard");
  46.         cardHolder.add(manageCustomerCard,"manageCustomerCard");
  47.         cardHolder.add(manageSaleCard,"manageSaleCard");
  48.         cardHolder.add(manageSaleBookCard,"manageSaleBookCard");
  49.         cardHolder.add(makeOrderCard,"makeOrderCard");
  50.         cardHolder.add(viewCartCard,"viewCartCard");
  51.  
  52.         manageCustomerBtn.addActionListener(this);
  53.         manageSaleBtn.addActionListener(this);
  54.         manageSaleBookBtn.addActionListener(this);
  55.         makeOrderBtn.addActionListener(this);
  56.         viewCartBtn.addActionListener(this);
  57.         exitBtn.addActionListener(this);
  58.  
  59.         c.gridwidth=1;
  60.         c.gridheight=1;
  61.         c.gridheight=1;
  62.         c.gridheight=1;
  63.         c.gridheight=1;
  64.         c.gridheight=1;
  65.         c.weightx=0;
  66.         c.weighty=0;
  67.         c.weighty=0;
  68.         c.weighty=0;
  69.         c.weighty=0;
  70.         c.weighty=0;
  71.         c.fill=GridBagConstraints.HORIZONTAL;
  72.  
  73.         addComponent(titleLbl,0,0,0,0,0,0);
  74.         addComponent(manageCustomerBtn,0,1,0,0,0,0);
  75.         addComponent(manageSaleBtn,0,2,0,0,0,0);
  76.         addComponent(manageSaleBookBtn,0,3,0,0,0,0);
  77.         addComponent(makeOrderBtn,0,4,0,0,0,0);
  78.         addComponent(viewCartBtn,0,5,0,0,0,0);
  79.         addComponent(exitBtn,0,6,0,0,0,0);
  80.  
  81.         add(cardHolder);
  82.         setVisible(true);
  83.     }
  84.  
  85.      public void addComponent(Component comp,int gx,int gy,int t,int l,int b,int r)
  86.     {
  87.         c.gridx=gx;
  88.         c.gridy=gy;
  89.         c.insets=new Insets(t,l,b,r);
  90.         gridBag.setConstraints(comp,c);
  91.         add(comp);
  92.     }
  93.  
  94.  
  95.  
  96.     public void createGUI()
  97.     {
  98.         model=new DefaultTableModel();
  99.  
  100.         int rows = 5,cols = 5;
  101.         model=new DefaultTableModel(rows,cols);
  102.  
  103.        // Object[] colNames={"Customer Id", "Customer Name","Customer Phone", "Customer Email"};
  104.        // model = new DefaultTableModel(null,colNames);
  105.  
  106.           Object[][] data={};//{,"",""},{,"",""}};
  107.           Object[] colNames={};//{"","",""};
  108.         model = new DefaultTableModel(data,colNames)
  109.         {
  110.             public boolean isCellEditable(int row,int col)
  111.             {
  112.                 return false;
  113.             }
  114.         };
  115.  
  116.         table=new JTable(model)
  117.         {
  118.             boolean[] cellEditables={false,true,true};
  119.             public boolean isCellEditable(int row,int col)
  120.             {
  121.                 return cellEditables[col];
  122.             }            
  123.         };
  124.  
  125.         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  126.  
  127.         scroll=new JScrollPane(table);
  128.         scroll.setPreferredSize(new Dimension(350,250));
  129.         panel=new JPanel();
  130.         panel.add(scroll);
  131.         add(panel);
  132.     }
  133.  
  134.     public static void main(String[] args)
  135.     {
  136.         new MainMenu();
  137.     }
  138.  
  139.  
  140.     public void actionPerformed(ActionEvent evt)
  141.     {
  142.  
  143.     }
  144.  
  145. }
  146.  
  147.  
Oct 24 '15 #1
1 1613
Rangan
8 New Member
Expand|Select|Wrap|Line Numbers
  1. static JPanel mainMenuCard, manageCustomerCard,manageSaleCard,manageSaleBookCard,makeOrderCard,viewCartCard;
You didnt create new object for those component then add into cardHolder component.
Jan 19 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

92
7549
by: Jeffrey P via AccessMonster.com | last post by:
Our IT guys are on a vendetta against MS Access (and Lotus Notes but they've won that fight). What I can't understand is, what's the problem? Why does IT hate MS Access so much. I have tried...
2
1340
by: santa19992000 | last post by:
Guys: Can somebody suggest a "C lang" project with pointers and linked lits for beginner?. Also is there anywahere I can find some C projects?. Thanks in advance.
21
2810
by: TAM | last post by:
Hi, I read that ASP.NET uses VB.NET instead of VBScript. I also read that ASP.NET is a subset of VB.NET. So if I learn VB.NET first then do I have the knowledge for programming ASP.NET...
3
1222
by: Wizard | last post by:
Hi All, Sorry for been a pain in the ass, but im looking everywhere and can't seem to find the answers. I would like to build a small ASP based site. I have 4 departments, and what i would...
1
1177
by: One Handed Man | last post by:
I suggest you put the connector onto the form and use the wizard to make your string for you, its easier that way. Once you have the right connection string you can remove the connector and code it...
5
1125
by: Ori :) | last post by:
Hey guys, I submitted a Q few days back about crystal reports chart, when I submitted my question I used the "notify me of replies". I guess there is a problem with that feature, because when I...
11
11504
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the...
14
1280
by: cool.vimalsmail | last post by:
i dont know how to convert a txt file into a zip file (i.e.,)i have a file named packages and i want the packages file with a ".gz" extension by implementing a python program
10
8574
by: dbproject2 | last post by:
Hello everyone, I was just looking for some feedback on my progress on a small project i took up for designing a database for my own little sports store. right now its just a prototype and...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.