GUI class question

Hi guys I use the NetBeans 6.0 and i build a project which has 2 Source packages on is my number game and the other I called GUI. In the GUI source package I drew a diagram which I want to use as my GUI to my number game but I don't know how to connect them. Now my question is this is it possible to connect them since they are in different packages? And my second queston is where should I code the action listenrs and where the event handler couse I am really new to gUI and that is my first one. Btw does net beans 6 provide some form of facility to join them both without much code? Thanks in advance!

1.I would say that using packages in this case is bad, but i wont since everyone else here thinks its always good. I would just use plain .java/.class files in the same directory so that they have free access to each other and the other files.
2. To use actions listener you first make your main class implement ActionListener, then addActionListener(this) to all your components that catch events, then use public void actionPerformed(ActionEvent e) to handle any events.

Similar Messages

  • Listen for events in another Gui class

    Most of the GUIs I have written to date have consisted of either a single class or multiple self-contained classes - mainly extensions of JPanel with JButtons etc to perform certain tasks.
    Now I want to be able to click a JButton in one class which will invoke a method in another.
    The code is too lengthy to post here but this is the general layout:
    JFrame Simulation_GUI contains a JPanel (panelMain) which is set as the content pane
    panelMain contains two GUI classes which extend JPanel;
    buttonPane > contains a number of JButtons, including the one I want to click
    loadingPane > contains the method (which takes a Hastable as an argument) I want to run
    All three panels are declared in the main class which extends JFrame, so I know that from there I can simply call;
    loadingPanel.runLoads(htData); but how do I do this from the JButton on the buttonPane.
    Any assistance greatly appreciated as I have little enough hair at the moment and can't afford to tear much more out.
    Thanks in advance

    Class GUI1 {
    //Display all the buttons.
    public void init() {
    Button.addActionListener(new
    ener(new SomeClass(this));
    Class SomeClass implements ActionListener {
    GUI1 gui = null;
    SomeClass(GUI1 gui) {
    this.gui = gui;
    public void actionPerformed(ActionEvent e) {
    //Do all your process here
    gui.setTable(table);    //table would be ur
    ould be ur hashtable
    }Cheers
    -PThis didn't fully answer my question but did two things:
    1. Told me that it is at least possible and it is just me having a senior moment,
    2. Sent me on the right road to finding a solution
    With additional help from the following post I have sorted my problem. Basically I had to centrallise the event handling into a different class. This was instantiated by the main GUI class and passed to the other GUI components as an argument.
    http://forum.java.sun.com/thread.jspa?threadID=576012&messageID=2881969
    Simple when you know how...!
    prashanth_kuppur - have some Duke Dollars on me and thanks for the poke in the right direction.

  • Use of swings- one class calling the gui class

    Hi,
    I have a class Manager and a class ManagerGUI.
    My ManagerGUI class looks somehting like this-
    public class ManagerGUI extends JFrame
    String name;
    JPanel namePanel;
    JTextField nameInput;
    JLabel nameLabel;
    Manager empAgent;
    ManagerGUI(Manager ea)
    super(ea.getLocalName());
    empAgent = ea;
    //make the name panel and add it to the topPanel.
    addListeners();
    getContentPane().add(topPanel, BorderLayout.CENTER);
    setResizable(false);
    }//end constructor.
    public void show()
    pack();
    super.setVisible(true);
    void addListeners()
    nameInput.addActionListener(new NameL());
    class NameL implements ActionListener
    public void actionPerformed(ActionEvent e)
    nameE = nameInput.getText();
    }//end class ManagerGUI.
    I have tried to seperate it out so that any changes can be easily implemented (although it perhaps is a long way of doing things).
    Now I have a class Manager that wants to call the GUI and then process the information got from the text field.
    I use the following lines to call the GUI class.
    manGui = new ManagerGUI(this);
    manGui.show();
    Is this the correct way of calling the GUI class?
    How do I get to use the variable nameE here, in the Manager?
    Thanks.

    Hi,
    I have no idea why you want to have an instance of Manager class in class ManagerGUI and an instance of ManagerGUI class in Manager class.
    I will create an instance of Manager in ManagerGUI and show the GUI there.
    In Manager you can create method that will accept the text from textfield in parameter.
    L.P.

  • Trying to pass parameters between GUI classes and methods

    Hi All.
    I have been working on a rather large final year project in college and it is getting close to the deadline. It looks as though I need to "tidy up" my code as it contains too many static methods, variables and other bad programming habits. My package consists of many different GUI's and classes. Up until now I have been calling different GUI's with guiName.NameOfMethod. I have been told this is bad practice so I am trying to fix this. Also instead of passing parameters correctly I have been creating static variables in my main class and using them. So for example if one class needed to pass a variable to the other I would first myGlobalVariable = X; in the first class. And then the second class can use this. This is also bad, right?
    So I guess im really just looking for a good example or tutorial on how to pass parameters between classes and methods, GUI if possible. Here is an example of how my GUI classes look:
    public class anotherGUI extends JFrame implements ActionListener {
            private JTextField a, b, c;
            private JButton button1, button2;
            JPanel p, p1;                   
            public anotherGUI() {
                LayOutAnotherGUI();
                setLocationRelativeTo(DnDMain.pictureArray[a]);
                setTitle("Example");
                setVisible(true);
                pack();     
            private void LayOutAnotherGUI(int c) {
         //GUI is layed out here     
            public void actionPerformed(ActionEvent e) {
                Object source = e.getSource();
                if (source == submit)
                    clickOK();
            public void clickOK(){
                //Here is where I have been accessing and modifying static global variables.  (But this needs to change).
    public void showanotherGUI() {
            new anotherGUI();
    }This is more or less how I have been going about creating my GUI's. These are used as pop ups. The user enters a value and then it is closed.
    To be honest I have been able to pass a variable correctly from one class to a GUI class but I have still having difficulty. For example in my code above I can pass the variable into this class but I cannot pass it into clickOK(). An this is where it is needed.
    Can anyone please help?
    I hope I have explained my problem well.
    Thanks in advance.

    I dont think that is what I need. An example of what I do in my program is:
    I have a main GUI with an array of images. There are a number of other small GUI's that appear for certain functions when the user clicks on an image or does some other function. I am trying to pass a value into the GUI class that is used for the smaller "pop up" GUI. So lets say the user has clicked the image in array[12]. Then a GUI is displayed. I need to pass the integer 12 into this class.
    Thanks.

  • Making middle teir accessible to all gui class objects.

    I'm designing a user interface at the moment for a
    3 tier application. I've got a good knowledge of Java
    but have never written a complicated gui with Swing.....
    User Interface (GUI) --> Business Logic (JDBC classes) --> MYSQL DB
    As the diagram shows, I want to keep the business logic separate
    from the user interface.
    My problem is that I'm not sure the best way to give all the GUI's action listeners
    access to the business logic object's methods which will call and return information
    from the database to the UI.
    Had there just been one UI class it would be easy to create an instance of the
    business logic class from the UI class, but
    the GUI is made up of many class objects with larger componets being made
    up of several smaller component classes and so on. What I guess I'm unsure of
    is what the standard practice is in this situation. Is a case of getting the GUI creation class
    to create an instance of the business logic object and then pass it down through the many
    GUI class constructors so that each GUI class object can reference it?
    You thoughts are appreciated, many thanks,
    Andrew.

    The commom practice here is to use some design patterns.
    The ones you need are Proxy and DTO (Data Transfer Object).
    The reasons behind using a proxy patters are that your DB could
    change location, and you could have multiple GUI's using the
    same DB
    You will have several DTO's which will contain the data from your
    database. These DTO's are used to group data common to one use
    case, so that in order to complete the use case, you only need to
    remotely access the DB once. These Dto's are regular Java objects
    with just getter and setter methods.
    Your GUI uses a Proxy object to request a DTO.
    someting like... you need some data to fill a form or a table?
    GUIProxy proxy = ProxyServices.getGUIProxy();
    FormDataDto dto = proxy.getFormData();
    JTexField nameField = new JTextField();
    nameField.setText(dto.getCustomerName());
    etc...
    Notice how your GUI has no idea where the data lives,
    how its stored, etc. It just knows how to request it.

  • Updating multiple GUI classes

    Hi,
    I'm wondering how it would be possible to have a class (class1) used for information, then two new classes (class2, class3) both used to display the same information from class1 in two seperate ways.
    So far I've put a variable in class2 and again in class3 that can be initialised to class1 at construction, so then all I do is just use class1's get() methods to get the information to display in class2 and class3.
    The problem is, I'm not sure how to make class2 and class3 update themselves every time the information in class1 changes.

    The GUI classes should register with the data class as change listeners. You'd typically create your own subclass of EventListener and EventObject. Add addXXXListner(), removeXXXListener and fireXXXListener methods to the data object. When the data changes the data objects first all the registered listeners, which can then query the new data in the normal way.

  • Can anyone help me change fonts and size on my page? I don't understand the class questions?

    Can anyone help me change fonts and size on my page? I don't understand the class questions? All I want to do is change the font and size of a table or div.
    http://www.allgearinc.com/AG12SSWL-Swift.htm -One problem page

    If you want to change the fonts of the entire page then this code will do the trick:
    body {
        font-size: 16pt;
        color: silver;
         font-family: whatever, goes, here;
    If you want to change the fonts of ALL tables on a page then the code is something like this:
    table {
        font-size: 20pt;
        font-family: "Courier New", Courier, monospace;
        font-style: italic;
        font-weight: bold;
    what exactly do you want to change?  Can you be a bit specific so that Ben or Ken can give you the exact code and tell you about the short-hand method to write the code in one line.
    Have you bought a book on CSS yet?  If not, it is a good idea to get one as a reference.  Eric Meyer writes good books on CSS.

  • Parent Class question

    I have a panel class with a slider on it .
    pseudocode:
    public class MyJSlider extends JPanel{
    private JSlider myjslider;
    private Color mycolor;
    public Color getColor(){return mycolor;}
    the action taken by the JSlider is to set mycolor to a new Color(r,g,b);
    My question, is there away to call the class that istantiated teh MyJSlider objects paint method from the
    JSlider action performed
    Something like
    slider_B.addChangeListener(
                   new ChangeListener()
                        public void stateChanged(ChangeEvent e)
         mycolor = new Color(R,G,slider_B.getValue());
    // super.paint() ????????

    If it's an inner class like that, it has access to the outer class's fields and final instance variables.
    You can access those methods implicitly.
    But you typically don't call paint() directly, you call repaint(), which issues a call to the GUI to repaint itself. (Although maybe it's different in Swing, I don't know.)
    When you post code please wrap it in [code] [/code] tags so it's easy to read.

  • Java GUI classes

    Hi,
    I created a simple aplication to store student data in a database.Got a set of classes like student.java subject.java teacher.java
    ,and another set of clases that produce the GUI screen.
    My question is,are the classes created for the GUI screen,included in the CLASS DIAGRAM?
    Would be good if some-one helps on this.
    Rahul

    The short answer to that is that there is no such thing as "the CLASS DIAGRAM". Imagine an application with hundreds of classes; a diagram drawn with all the classes and their relationships would be unreadable. When I want to draw a class diagram I start with the caption -- all good diagrams, not matter what kind, have a caption, right? Given your caption, only include the classes and relationships that are relevant to the caption. When you think of the problem from that angle, it becomes trivial.

  • Inner Class Question

    My question pertains to the code at the bottom of this post.
    I don't understand why the compiler doesn't give an error for the line below. Why would it let you refer to something inside the class (in this case I'm referring to ClassWithInnerClass.MyInnerClass) unless it were static?
    ClassWithInnerClass.MyInnerClass mic = cwic.retMyInnerClass();To illustrate why I'm asking, I created 2 ints ("regularInt" and "staticInt") inside class "ClassWithInnerClass". The compiler let me set the value of "staticInt" from within main whereas it wouldn't let me do so w/ "regularInt" (which is why I commented that line out). Don't get me wrong though - I understand the reasons why the compiler behaves as it does for "regularInt" and "staticInt". I understand that a static variable can be accessed without instantiating a class (and that there's only 1 created no matter how many classes are instantiated). I also understand that, to access a non-static variable, you need to instantiate a class. My question arises only because of trying to extend that logic to MyInnerClass.
    I can already take a guess that the answer is going to be something like, "the reason it works this way is because class 'MyInnerClass' is just a declaration NOT a definiton". I guess I just want confirmation of this and, if possible, some reasoning behind this logic.
    HERE'S THE CODE...
    class CreateInnerClasses {
         public static void main (String args[]) {
              ClassWithInnerClass cwic = new ClassWithInnerClass();
              ClassWithInnerClass.MyInnerClass mic = cwic.retMyInnerClass();
              //ClassWithInnerClass.regularInt = 5;
              ClassWithInnerClass.staticInt = 10;
              mic.printIt();
    class ClassWithInnerClass {
         public int regularInt ;
         static public int staticInt;
         class MyInnerClass {
              void printIt() {
                   System.out.println("Inside ClassWithInnerClass.myInnerClass");
         MyInnerClass retMyInnerClass () {
              return new MyInnerClass();

    The line    ClassWithInnerClass.MyInnerClass mic = cwic.retMyInnerClass();is accepted because the name of the inner class is ClassWithInnerClass.MyInnerClass. This has nothing to do with accessing fields even though the syntax is similar.
    On the other hand, the line    SomeClassWithAnInnerClass.InnerClass ic = new SomeClassWithAnInnerClass.InnerClass();is not accepted because the nested class SomeClassWithAnInnerClass.InnerClass is not static: you must have an instance of the outer class available. The correct syntax for calling the constructor of the inner class would be    Outer.Inner instance = outerInstance.new Inner();In this case you could write:    ClassWithInnerClass.MyInnerClass mic =  new SomeClassWithAnInnerClass() . new InnerClass();
        // OR:
        ClassWithInnerClass.MyInnerClass mic =  cwic . new InnerClass();The Java tutorial has a pretty good explanation on nested classes:
    http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html
    http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html

  • Some newbie POWL feeder class questions

    Hi,
    I'm just working with POWLs resp. the associated feeder class. At the moment I have two question that hopefully could be answered by someone:
    1) Is it possible to modify the UI layout of the selection criteria in a way that they will be displayed in a configurable number of columns and not just one below the other?
    2) I declared some criteria with "ls_seldef-kind = c_type_param.". The user should be able to work with wildcards for these criteria (option "CP"), but the criteria values given to the GET_OBJECTS method always do have the "EQ" option. This is not really useful for e.g. description fields. How can I change this?
    Many thanks in advance for any help.

    I also hope I can know how to do .
    Pleae tell me if you have solved the problem .
    Best regards ,

  • Connecting my GUI class to my Game class

    Hi guys I build my GUI with netBeans 6.0 and I used a seperate source package for my number game and for my GUI. Now I know I have to make one of the main classes extending an Action Listener but I don't know which one the main class of the game or the main class of the GUI. And is it possible to connect them if they are in seperate packages, although I assume everything is possible. Thanks in advance!

    The problem is solved.

  • Importing Java Class Question

    Hello,
    Sorry for such a newbie question and such a long post, I did remember how to do this before but now I can't for the life of me remember. Anyhow, I have a simple question about importing custom-made java classes, from another directory in the windows operating system. I have the classpath set, and also I realize that because the two files below are in the same directory theres no need for an import statement as Java will look for the class in the same directory.
    But I would like to know how the import statement is suppose to look to import a custom made java class from another directory, (assuming of course that I set the correct classpath)
    here's the java class location:
    c:\school\csc365\narcus.java
    //narcus.java
    import java.io.*;
    class narcus implements Comparable
    String firstName = "firstName";
    String lastName = "lastName";
         public narcus()
         firstName = firstName;
         lastName = lastName;
         public narcus(String f)
         firstName = f;
         lastName = lastName;
         public narcus(String f, String l)
         firstName = f;
         lastName = l;
    public String getFirst()
    return "first..";
         public int compareTo(Object e)
         return 1;
    Here's the location of the driver program thats suppose to use the narcus.java class
    c:\school\csc365\test.java
    //test.java
    //import statement? maybe import "c:\\school\\csc365\\*"; ?
    import java.io.*;
    class test
    public static void main(String[] args)
         narcus jim = new narcus();
         System.out.println("omg\n");
         System.out.println(jim.getFirst());
    And also, here is my classpath:
    PATH=c:\school\csc365\;c:\school\
    The classpath also points to the jdk libraries and few other directories but I didn't write that above, as it probably isn't relevant.
    I've tried the following import statements.
    import "c:\\school\csc365\\narcus.java";
    import "narcus.java";
    import "c:\\school\\csc365\\*";
    But I keep getting an error that says:
    test.java:1 <identifier> expected
    Any help is appreciated!

    Hi Folks,
    I am new to this forum, heard that interesting discussions always happens on this forum so immediately registered,don't want to miss any oppurtunity to participate in discussions.
    I have pretty much basic question regarding compiling and exceuting files in different packages.I have the following directory structure
    C:\Projects\WDPROEast\Development\CommonService\Code\Java from where java files stored in different packages as follows:
    com\wdpro\commerce\common\crm\dae\nautilus\adapter directory has java files in com.wdpro.commerce.coomon.crm.dae.nautilus.adapter package.
    com\wdpro\commerce\common\dae\exception has java files with package named com.wdpro.commerce.common.dae.exception.
    com\wdpro\commerce\common\dls\exception has java files with corresponding package name.
    com\wdpro\commerce\common\dto has java files under proper package name.
    com\wdpro\commerce\common\exception has java files with appropriate package name.
    com\wdpro\commerce\common\util has java files with package name. I am starting at Java Directory,want to compile and run file named a.java in com.wdpro.commerce.coomon.crm.dae.nautilus.adapter package with having all other java files on classpath as follows
    so I issued command for compilation as follows C:\Projects\WDPROEast\Development\CommonService\Code\Java>javac com/wdpro/commerce/common/crm/dae/nautilus/ada
    pter/a.java com/wdpro/commerce/common/crm/dae/nautilus/adapter/NautilusServiceUtility.java com/wdp
    ro/commerce/common/crm/dae/nautilus/adapter/URLReader.java com/wdpro/commerce/common/crm/dae/nautilus/adapter/
    b.java com/wdpro/commerce/common/dae/exception/*.java com/wdpro/commerce/common/dto/*.java
    com/wdpro/commerce/common/exception/*.java com/wdpro/commerce/common/util/*.java com/wdpro/commerce/common/dl
    s/exception/*.java It compiled greatly but when I issue command to run a.class file as
    C:\Projects\WDPROEast\Development\CommonService\Code\Java>java com/wdpro/commerce/common/crm/dae/nautilus/adap
    ter/UtilityAccesssit's giving following exception
    Exception in thread "main" java.lang.NoClassDefFoundError: com/wdpro/commerce/common/crm/dae/nautilus/adapter/
    UtilityAccesssbut when I run a.java with the following command
    C:\Projects\WDPROEast\Development\CommonService\Code\Java>java com/wdpro/commerce/common/crm/dae/nautilus/adap
    ter/UtilityAccess com/wdpro/commerce/common/crm/dae/nautilus/adapter/NautilusServiceUtility.java com/wdpro/com
    merce/common/crm/dae/nautilus/adapter/URLReader.java com/wdpro/commerce/common/crm/dae/nautilus/adapter/Nautil
    usAccessUtility.java com/wdpro/commerce/common/dae/exception/*.java com/wdpro/commerce/common/dto/*.java com/w
    dpro/commerce/common/exception/*.java com/wdpro/commerce/common/util/*.java com/wdpro/commerce/common/dls/exce
    ption/*.javaSo my question do I need to add all required java files to path when required class files are under different packages?is it manadatory.
    I hope you understand my question,pass me any comments you may have.
    Thanks alot,
    Anu

  • The arrays class question

    consider the code below
    int[] list = {2, 4, 7, 10};
    java.util.Arrays.fill(list, 7);
    java.util.Arrarys.fill(list, 1, 3, 8);
    System.out.print(java,util.Arrays.equals(list, list));i understand line 2, it gonna fill 7 into the array,so the output would be Line 2: list is {7, 7, 7, 7}
    my question is line 3, how come the output would be {7, 8, 8,7} what does 1 and 3 represent in a arrary?
    the line 4 output would be {7, 8,8,7} again why?
    Thank you guys whoever is gonna take to respond me questions

    zerogpm wrote:
    but which 2 lists were comparing ? since i have list list with the same name1) You're not comparing lists, you're comparing arrays.
    2) You're comparing a single array with itself.
    3) Objects, including arrays, do not have names. Classes, variables, and methods have names. Objects do not.

  • Where is the getString() implementation for RS and Object class question

    Dear all,
    I had these two questions ringing since a long time.
    1)ResultSet is an interface.
    In my jdbc code I have generally written rs.getString() and rs.getInt etc.. without giving a second thought as to where exactly is this getter implemented !
    I have RTF API .. without too much help.
    Could some one kindly explain Where is the implementation of the getString method ?
    2) Could you please tell why the Wait() Notify() and NotifyAll methods have been implemented in the Object class ? What was the need to define em in the Object class ?
    Thanks in advance for your time spent on this.
    Rgds

    Sarvananda wrote:
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    Rgds
    >
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    A desire to not have to couple your code to a particular database and JDBC driver. It's a classic example of the abstract factory pattern

Maybe you are looking for

  • How can i remove my primary apple id

    I have 2 email address in my apple ID my apple ID & primary email address is:  ***@yahoo.com & my alternate email addresses is:  ***@me.com my alternate email was created using the primary email in iCloud Setting. but now, I want remove this yahoo em

  • IPOD TOUCH NOT WORKING WITH ITUNES

    I am using: iPod Touch 16GB 1.1.4 (With $25 Software Upgrade) Windows Vista Premium Edition iTunes 7.6.2 Whenever I connect my iPod, the device connect sound is made and it shows up in the my computer window, but it will not show up or sync with iTun

  • Document storage advice required

    Good day, Our developers are doing a project that involves processing Purchasing Invoices that have been scanned and converted to PDF. They are using ArchiveLink and at the moment are storing these documents directly in the database. They(developers)

  • Validating SQL expressions

    Hello, Am researching a way for validating SQL expressions. Say I have expressions substr(<tname.coumn_name>,1,2), I want to parse this expression for completeness, meaning whether the expression can be used in a case, decode or a normal select state

  • Using execute immediate for select

    Hi all, i am writing a procedure as follows: create or replace procedure ( run_yr_mo in number) as v_count number := 0; begin execute immediate 'select count(*) from all_tables where owner = ''MGR'' and table_name = ''FC_PR_'''||run_yr_mo||'' into v_