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.

Similar Messages

  • 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.

  • 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.

  • 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.

  • 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.

  • Cannot connect two computers to the same game server HELP!

    I have a Linksys WRT54G Router.  I have two computers and I want to be able to use them on the same gaming server.  Unfortunately, the game only have one port, so I can only port forward one of my computers.  How can I configure my router to have two external IP addresses to the server so it won't kick one of my computers out.  Thanks!

    Hi,
    I am in a gaming community and many members have a Linksys at home (but I don't know which kind exactly). Many of us try to connect two computers to the same server (many have a family). It seems it is a common problem that no one can connect two computers to the same game server.
    I have a BEFSR41 V3 Firmware version 1.04.8
    I use fixed IP address and no connectivity problem on Internet.
    I have win XP SP2 on both computer.
    I am using a DSL modem
    I can connect the two computers to two different game servers at same time, but not the same server. Default port for this game is the same for all servers I use. I tried with both port forwarding enabled (in that case one PCs can connect the other not) or not (in the second case, whenever the second PC connects, the first one lose his connection to the server, no mater the order I try to connect my PCs).
    Now the weird thing is that one member in my community just decided to throw away his Linksys router and he bought another brand (which I won't name to remains politically correct). Now, without changing anything in his PCs or his connection type, he can now play with two PC on the same server.
    I am seriously thinking doing the same move. Since more and more game are now using Internet (and servers that controls piracy, $$) and family want to play together, not being able to connect two PCs on the same game server makes Linksys in bad situation from marketing point of view.
    For example, in my gaming communtity, we now all know that Linksys can't handle two PC on same server, but other brand can...
    Thank you in advance for your help.

  • Repository connection information gui question

    I am going through the "Getting started with oracle data integrator" document (E12641-01). I am at the part where I am supposed to create a work repository(step 5 of page 4-4). Unfortunately, the repostory connection information gui will not allow me to input a name for the work repository in the little text field. The cursor blinks but no text appears when I type. It is as if the text field is locked.
    The following describes my system configuration:
    Microsoft Windows Server 2003 R2 Standard x64 Edition Service Pack 2
    Oracle Data Integrator 11g Standalone Edition Version 11.1.1
    Build ODI_11.1.1.3.0_GENERIC_100623.1635
    Java(TM) Platform 1.6.0_25-ea
    Oracle IDE 11.1.1.3.0
    WebLogic server 10.3
    Oracle Server 11gR1
    I have both JDK 32bit and 64bit packages installed on my 64-bit machine. Apparently, odiclient only works with 32-bit jdk package.

    Question solved:
    http://st-curriculum.oracle.com/obe/fmw/odi/odi_11g/ODImaster_work_repos/ODImaster_work_repos.htm

  • Trouble with connecting a gui to a database

    I have been trying to follow the connecting a GUI to a Java DB Database with Netbeans IDE tutorial. But when I try to download the GUI BD Exercise Initial (which it states is needed to complete the tutorial) it does not download it. I have looked in the Projects section but it does not appear but when I try to download it again and again it states that it there.
    Does anybody know of any other site that has a Tutorial that describes the same thing. Or does any body know the procedure needed at this stage onwards to connect the GUI to a database. I have completed all of the other Tutorials successfully and can get my database connected to netbeans and create tables etc. Just can't connect it to a GUI.
    I don't know if there could be a problem because the file is zipped it seems unlikely to me. In any case when I download it nothing shows in the projects section like it should do although I have been able to save it to other parts of my computer hard drive, but when I try to send it the netbeans Myprojects file it is unsuccessful.
    I have the URL of the Tutorial that I have had the trouble downloading the file from. http://www.netbeans.org/kb/55/gui-database.html
    I wonder if any body else has had trouble downloading this link?
    Any way I would really appreciate any feedback on this has anybody else had trouble on this tutorial?

    JDBC Database Access
    http://java.sun.com/docs/books/tutorial/

  • Proper GUI classes decomposition

    Hello,
    I would ask for advice more experienced programmers how do you implement dependencies between business logic and GUI. In particular decomposition of GUI into classes - interactions between them, how it's everything connected with business logic.
    Let's say I have couple of windows (panes) on which are placed text fields, buttons and other controls. For each one I create separate class - but what I should put into this class? Definition of controls, those appearance, placement on panes, resize behavior? Should I also in this class attach actions to those controls? Or should I create the separate class defining those actions?
    Now about data model (MVC pattern) - I assume that it's a bridge between business logic and GUI, but how to connect it properly and attach to window? (Which class create which one, which one holds a reference to another and so on...)
    As an example let's take a window with two text fields and one button. The content of one text field is defined somewhere in business logic - it's the output of some algorithm. Second text field is an input, and the button starts the algorithm. So it's something like:
    public class BusinessLogic {
        String algorithmInput;
        String algorithmOutput;
        String runAlgorithm(String iput) {
            // something
    }How should I write GUI for this? (classes decomposition and references between them)
    Thanks in advance for all your advices and for patience for beginner programmer :)

    I generally go by this rule of thumb:
    The middle tier objects usually have, at least, 2 layers in them--
    layer 1 -- UI support, this includes all of the rules and structure to allow the data to be easily collected/viewed by the user--they are structured around the UI and how the users want to view their data.
    layer 2 -- actual DB interface objects needed to facilitate data transfer to and from the DB and to make sure integerty is enforced.
    These layers can be subdevided as needed and even other layers may be added depending on project requirments.

  • How to use Forms Default Database Connection in java class

    When a form based application is started, a connection is made with underlying database. This is the Default (Primay) Database Connection.
    The problem is I have some of my business logic implemented in a java class. In this class I have to make a another connection with the same database. What I want to do is to use the original Database Connection in the java class. In this I may avoid the overhead of reconnection.
    Could anyone pls guide me in this way...

    you can't share the forms connection. Sorry :(

  • Getting error while Creating a JDBC connection from Java Class

    Hi,
    I am getting the exception pasted below:
    Exception in thread "main" java.lang.AbstractMethodError
    at JvMakeVTable(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at JvPrepareClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at JvWaitForState(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0)
    at oracle.jdbc.driver.OracleStatement.executeQuery(java.lang.String) (Unknown Source)
    at oracle.jdbc.dbaccess.DBAccess.setNlsParamsClient(oracle.jdbc.driver.OracleConnection) (Unknown Source)
    at oracle.jdbc.ttc7.TTC7Protocol.initNls(oracle.jdbc.driver.OracleConnection) (Unknown Source)
    at oracle.jdbc.driver.OracleConnection.OracleConnection(oracle.jdbc.dbaccess.DBAccess, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Properties) (Unknown Source)
    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Properties) (Unknown Source)
    at oracle.jdbc.driver.OracleDriver.connect(java.lang.String, java.util.Properties) (Unknown Source)
    at java.sql.DriverManager.getConnection(java.lang.String, java.util.Properties) (/usr/lib/libgcj.so.5.0.0)
    at java.sql.DriverManager.getConnection(java.lang.String, java.lang.String, java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    The code raising this error is :
    try
                   Class.forName("oracle.jdbc.driver.OracleDriver");
              catch (Exception Exp)
                   System.out.println("Error while getting the class : "+Exp);
    try
                   String url = "jdbc:oracle:thin:@hostname:port:SID";
                   String user = "apps";
                   String password = "password";
                   con = DriverManager.getConnection(url,user,password);
    catch (Exception ex)
                   System.err.println("SQLException: " + ex.getMessage());
    Any help in this is appreciated.
    Regards
    Jujaar

    Why do you have the Class.forName() in a separate try-catch block than the DriverManager.getConnection()?
    Try placing everything in the same try-catch block to see if that resolves your problem.
    You may also want to try using an OracleDataSource.
    OracleDataSource ods = new OracleDataSource();
    String url = "jdbc:oracle:thin:@//hostname:port/SID",
    ods.setURL(url);
    ods.setUser("apps");
    ods.setPassword("password");
    Connection conn = ods.getConnection();
    Refer to http://st-doc.us.oracle.com/11/111/java.111/b31224/getsta.htm#i1008334 for details on how to connect to the database using a Data Source.

  • Calling DB connection from another class

    Hi I am trying to create a method in another class to call another method that checks for userid in DB? What is the best way to set this up? I.e. calling method?
    //calling method below line
    private boolean setuserExist(String username) {
         else return false;
    public String getserExist() {
              return userexist;
    // Method being called below this line
    public boolean userExist(String username){
              boolean exist = false;
              System.out.println("in LoginDBAccess: username is " + username);
              try{
    Connection conn = dbc.getConnection();
    Statement statement = conn.createStatement();
    String query =      "SELECT User.UserID " +
                        "FROM User " +
                        "WHERE User.UserID = '" + username + "'";
    ResultSet resultSet = statement.executeQuery(query);
    System.out.println("1.1");
    ArrayList result = new ArrayList();
    while(resultSet.next()){
         //System.out.println("In While:");
    ArrayList item = new ArrayList();
    item.add(resultSet.getString("UserID"));
    result.add(item);
    System.out.println("LoginDBAccess Count: " + result.size());
    conn.close();
    if (result.size() == 1){
         exist = true;
              }catch(Exception e){
         e.printStackTrace();
              return exist;
         }

    Cross-post
    http://forum.java.sun.com/thread.jspa?threadID=603496

  • How is better to connect, use a class or ..

    hi,
    i have a web application with ten classes. I hava a class DatabaseClass which provides only the connection to the database with a method call getMyConnection f.i.
    I thought to remove this class and put the databse conncetion
    String(server name,database name ,user,pass..) to the web.xml file and let other classes to call this parameter from web.xml and make own connnection instead of to create an instance of DatabaseClass. What could be a problem, what is advantage, disadvantage.?
    thanks

    I don't know, it's your idea.

Maybe you are looking for

  • Fact Sheet

    Hi forum, the transaction information of a BP in the factsheet are not displayed in the sequential order i.e the activities date in the factsheet are showing as the date of creation rather than showing the actual date of the activity.For instance,if

  • Is there any way to use video with the new Flash CC HTML5 Canvas?

    I am a long time Flash user trying to determine if this new version of the program is something to add to the workflow again (after the last several years of not being able to use it) and the tutorials I have seen are not well written. Is there a way

  • Uploading Music from PC to NEW Handset!

    Hi My Nokia 5800 handset has recently died after having it for 3 months, and I received a new 5800 handset from orange. I saved my music to my sim card but I am now unable to play it and the error sign reads 'Unable to play. License invalid. Get lice

  • Creating a QT Master for a Digital cinema Screening.

    Hello, I'm preparing a film for a Digital Cinema release. We shot it DVCPRO HD 1920x1080 25fps progressive and we are delivering a TIFF video file with the same specs. They will then be upresing that to a 1998 x 1020 DCP file. My concern is that the

  • Export preferences stopped working

    Hi, I have Gargageband 3. I am recording in Podcast and was using Garageband preferences to be ablt to export to iTunes at two different qualities, one for spoken podcast, one for musical. It was working fine, then stopped. Now it just exports to iTu