473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

crazy problem..help me.

hi,
My problem is some what crazy for me.

Let's see,

I declare one java file named as, test1.java.
In which i designed required GUI for project i.e 8 combobox,two buttons,etc.

Second file is automatic.java in which I get the selected values of combobox by creating the object of test1.java file.
like
test1 tst=new test();

and access value of combobox like
String cmb = tst.cmbv1;

Same as above getting the values of combobox in third file and fourth file.

but when I create the object of class test1,GUI for test1 is executed.

And this is what the problem I faced i.e. 3 times GUI frame for test1 is displayed.

Please tell me how to overcome this problem.Thanks in advance.

Thanks,
Vikas Sawant.
Mar 12 '09 #1
3 1427
JosAH
11,448 Expert 8TB
So you must've created three JFrames, i.e. you have called the constructor for your GUI class three times. You didn't show us any code so we can't give you more details. A few System.out.println() statements on strategic places would soon show you your mistake.

kind regards,

Jos
Mar 12 '09 #2
hi,
My code for test1.java is as fallow
Expand|Select|Wrap|Line Numbers
  1. import java.awt.Font;
  2.  
  3. public class test1 extends JFrame implements ActionListener 
  4. {
  5.  
  6.   JFrame frame;
  7.   JLabel lbl= new JLabel(); 
  8.   String[] offense = { "HR", "RBI", "SB", "AVG"};
  9.   String[] pitching = { "W", "S", "ERA", "WHIP"};
  10.   String[] cmbint={"0","10","20","30","40","50","60","70","80","90","100"};
  11.   //String[] cmbhr2={"0","10","20","30","40","50","60","70","80","90","100"};
  12.   String[] cmbfloat={"0.200","0.210","0.220","0.230","0.240","0.250","0.260","0.270","0.280","0.290","0.300","0.310","0.320","0.330","0.340","0.350"};
  13.   String[] cmbws={"0","2","4","6","8","10","12","14","16","18","20"};
  14.   String[] cmbera = {"1.0","1.5","2.0","2.5","3.0","3.5","4.0","4.5","5.0"};
  15.   String[] cmbwhip = {"1.00","1.10","1.20","1.30","1.40","1.50","1.60","1.70","1.80","1.90","2.00"};
  16.  
  17.   JButton create,cancel;
  18.   JComboBox Oone,Otwo,Othree,Ofour,Pone,Ptwo,Pthree,Pfour;
  19.   JComboBox Oone2,Otwo2,Othree2,Ofour2,Pone2,Ptwo2,Pthree2,Pfour2;
  20.   public JComboBox hr1,hr2,rbi1,rbi2,sb1,sb2,avg1,avg2;
  21.   public JComboBox s1,s2,w1,w2,era1,era2,whip1,whip2;
  22.   public JComboBox rbi11,rbi21;
  23.  
  24.   static String hrv1,hrv2,rbiv1,rbiv2,sbv1,sbv2,avgv1,avgv2,wv1,wv2,sv1,sv2,erav1,erav2,whipv1,whipv2;
  25.  
  26.  
  27.  
  28.  
  29.   public test1()
  30.   {
  31.  
  32.     frame = new JFrame("Order Of logic");
  33.     frame.setSize(675,560);
  34.     addWindowListener(new WindowAdapter() 
  35.     {
  36.       public void windowClosing(WindowEvent e) 
  37.       {
  38.         System.exit(0);
  39.       }
  40.     });
  41.  
  42.  
  43. try
  44. {
  45.  
  46.     JPanel title = new JPanel();
  47.     title.setLayout(new GridLayout(2,1,5,30));
  48.     JLabel OLabel = new JLabel("Offense :-",JLabel.CENTER);
  49.     title.add(OLabel);
  50.     JLabel PLabel = new JLabel("Pitching :-",JLabel.CENTER);
  51.     title.add(PLabel);
  52.  
  53.     ///////////////////////// offense combo box
  54.  
  55.     JPanel o = new JPanel();
  56.     o.setLayout(new GridLayout(1,4,25,30));
  57.  
  58.     Oone = new JComboBox(offense);
  59.     o.add(Oone);
  60.  
  61.     Otwo = new JComboBox(offense);
  62.     o.add(Otwo);
  63.  
  64.     Othree = new JComboBox(offense);
  65.     o.add(Othree);
  66.  
  67.     Ofour = new JComboBox(offense);
  68.     o.add(Ofour);
  69.  
  70.     ///////////////////////////// pitching combo box
  71.  
  72.     JPanel p = new JPanel();
  73.     p.setLayout(new GridLayout(1,4,25,30));
  74.  
  75.  
  76.     Pone = new JComboBox(pitching);
  77.     p.add(Pone);
  78.  
  79.     Ptwo = new JComboBox(pitching);
  80.     p.add(Ptwo);
  81.  
  82.     Pthree = new JComboBox(pitching);
  83.     p.add(Pthree);
  84.  
  85.     Pfour = new JComboBox(pitching);
  86.     p.add(Pfour);
  87.  
  88.  
  89.  
  90.    Oone.setSelectedIndex(0);
  91.     Otwo.setSelectedIndex(1);
  92.     Othree.setSelectedIndex(2);
  93.     Ofour.setSelectedIndex(3);
  94.  
  95.     Oone.addActionListener(this);
  96.     Otwo.addActionListener(this);
  97.     Othree.addActionListener(this);
  98.     Ofour.addActionListener(this);
  99.  
  100.     Pone.setSelectedIndex(0);
  101.     Ptwo.setSelectedIndex(1);
  102.     Pthree.setSelectedIndex(2);
  103.     Pfour.setSelectedIndex(3);
  104.  
  105.     Pone.addActionListener(this);
  106.     Ptwo.addActionListener(this);
  107.     Pthree.addActionListener(this);
  108.     Pfour.addActionListener(this);
  109.  
  110.  
  111.     TitledBorder tcriteria;
  112.     tcriteria = BorderFactory.createTitledBorder("Select Order Of Logic ");
  113.  
  114.     ////////////////////////////////// panel for buttons
  115.  
  116.     JPanel box= new JPanel();
  117.  
  118.  
  119.     create=new JButton("Create Team");
  120.     box.add(create);
  121.     create.addActionListener(this);
  122.  
  123.     cancel=new JButton("Cancel");
  124.     box.add(cancel);
  125.     cancel.addActionListener(this);
  126.  
  127.  
  128.  
  129.  
  130.     ///////////////////        Panel for order of Logic
  131.     JPanel m= new JPanel();
  132.  
  133.     m.setLayout(new GridLayout(2,2,30,20));
  134.     m.add(o);
  135.     m.add(p);
  136.  
  137.     JPanel mn = new JPanel();
  138.     mn.setBorder(tcriteria);
  139.     mn.add(BorderLayout.WEST,title);
  140.     mn.add(BorderLayout.CENTER,m);
  141.  
  142.  
  143.  
  144.     /////////////////////////////////  arrangment at frame
  145.  
  146.  
  147.     frame.add(BorderLayout.NORTH,mn);
  148.  
  149.     frame.add(BorderLayout.SOUTH,box);
  150.  
  151.  
  152.     frame.setVisible(true);
  153. //    frame.setResizable(false);
  154.  
  155.  
  156.     }catch(Exception e)
  157.     {
  158.         System.out.println(e);
  159.     }
  160.  
  161.  
  162. }
  163.  
  164.   public void actionPerformed(ActionEvent e) 
  165.   {
  166.  
  167.     try
  168.     {
  169.  
  170.      if(e.getSource()==cancel)
  171.     {
  172.         System.exit(0);
  173.         }
  174.  
  175.     else if(e.getSource()==create)
  176.     {
  177.         category[0] =(String)Oone.getSelectedItem();
  178.         category[1] =(String)Otwo.getSelectedItem();
  179.         category[2] =(String)Othree.getSelectedItem();
  180.         category[3] =(String)Ofour.getSelectedItem();
  181.  
  182.         category[4] =(String)Pone.getSelectedItem();
  183.         category[5] =(String)Ptwo.getSelectedItem();
  184.         category[6] =(String)Pthree.getSelectedItem();
  185.         category[7] =(String)Pfour.getSelectedItem();
  186.  
  187.          final Automatic1 automatic1 = new Automatic1(category[0],category[1],category[2],category[3],category[4],category[5],category[6],category[7]);
  188.  
  189.      frame.setContentPane(automatic1);
  190.  
  191.      frame.setLocation(250,150);
  192.      frame.setSize(750,650);
  193.      frame.setVisible(true);
  194.  
  195.     }
  196.  
  197.     }catch(Exception e1)
  198.     {
  199.         System.out.println("hi..."+e1);
  200.     }
  201.  
  202.   }
  203.  
  204.   public static void main(String[] args)
  205.   {
  206.     test1 tst = new test1();
  207.  
  208.   }
  209. }
  210.  






This is the code for test1.java.
when I wanna use the value of combo box in another file.I write code their as

test1 tst = new test1();
String s =tst.cmb1;

and use above code in two files. So when i declare like this test1() constructor called and GUI is displayed. Which I don't want.

I want only at first GUI displayed and when I clicked on button appropriate operation performed.but when I clicked on button and go for next class in which value of variables of test1 is accessed by object of test1 like given above. but because of this GUI displayed 3 times.

How can I overcome this problem.?
Please help me.


Thanks,
vikas sawant
Mar 13 '09 #3
JosAH
11,448 Expert 8TB
@vikassawant
There's more trouble: your test1 class is a JFrame because it extends from it but it also has a JFrame because it has a member variable of that class. IMHO that's one JFrame too many.

If you want another class to be able to use that (single) instance of your test1 class you should either pass it as a parameter to, say, the constructor of that other class or you should make that test1 object available in another way. That ugly little singleton pattern comes to mind.

kind regards,

Jos
Mar 13 '09 #4

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

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
11
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
8
by: Islam Elkhayat | last post by:
I need help plzzzz... In my windows application i fill listview from simple access database... here is the code //Creating colums InitializeComponent();...
3
by: Larry Tate | last post by:
I have had a monstrous time getting any good debugging info out of the .net platform. Using ... ..NET Framework 1.1 Windows 2K Server VB.NET <- is this the problem? error handling in the...
1
by: Maileen | last post by:
Hi, I'm still with my problem of string resource to load from a C++ DLL. Here is my code : in my module i have the function for loading DLL and sending back a string to main form. where...
0
by: Aws | last post by:
My crazy GridView !! I am using Visual Studio 2005, I have a problem with my GridView. I have one access .mdb table and when I update a record on the table EVERYTHING is perfect. I made a Web...
3
by: Bob Bedford | last post by:
I understand nothing about the rights ! I create directories and subdirs by php scripts. I've an admin accound, and trying to delete files by FTP, I've not the right to. Admin should have ALL...
3
by: rashpal.sidhu | last post by:
Please help, this problem is driving me crazy !! I am using metaphone to create phonetic keys. When i run the module stand-a-lone it works fine. I'm trying to create a runner for informix...
1
by: DaMasta | last post by:
hi..im new to the community and was finally so fustrated with guessing that i figured i'd try to get some help (and from my writing..you can probably tell im not exactly 40 years old) oki..here's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.