Linking two class files?

hello!
I have a class called paul.java and a class called trialgrid.java...
paul.java is a menu screen that simply has four buttons, one of the buttons is called btnOnePlayer, trialgrid.java is a battleships game that is one player!
my question is how do i get it so that when a user clicks on btnOnePlayer in paul.java it opens the trialgrid.java game of one player battleships??
any help would be amazing, thank you!!!!

this is a great question for this forum. Here is a code snippet that shows one way to use the ActionListener. You may also want to look into using Adapters. You could post another question about the Adapters and see what you get. Anyway, here is the code.
Paul.java
import javax.swing.* ;
import javax.swing.event.* ;
import java.awt.* ;
import java.awt.event.* ;
public class Paul implements ActionListener {
public Paul () {
   //do nothing in constructor since it happens in main
   //if this were part of bigger code, then constructor
   //may need to put GUI together
private static void createAndShowGUI (Paul paul) {
   JFrame frame = new JFrame ("Battle Ship") ;
   Container pane = frame.getContentPane() ;
   pane.setLayout (new BorderLayout()) ;
   JButton onePlayerButton = new JButton ("One Player") ;
   //here is the action connection. The Paul class (which is "this")
   //implements the Actionistener interface. See the method below
   //call actionPerformed. This comes from the implementation of
   //ActionListener. When the button is clicked the code in the
   // actionPerformed method is exectuted.
   onePlayerButton.addActionListener (paul) ;
   pane.add (onePlayerButton, BorderLayout.CENTER) ;
   frame.pack() ;
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
   frame.setVisible(true) ;
public void actionPerformed (ActionEvent ae) {
   //since I know that the only way into the method is
   //from the onePalyerButton, I do not have to check
   //how I got here. I just do the work.
   TrialGrid grid = new TrialGrid () ;
   grid.showGrid () ;
public static void main (String[] args) {
     javax.swing.SwingUtilities.invokeLater(new Runnable() {
       public void run() {
           Paul paul = new Paul() ;
           createAndShowGUI(paul);
Here is the TrialGrid.java that pops up with the button
import javax.swing.* ;
public class TrialGrid extends JFrame {
public TrialGrid () {
public void showGrid () {
   this.getContentPane().add (new JLabel ("ONE PLAYER")) ;
   this.setSize (500,500) ;
   this.setVisible (true) ;
}

Similar Messages

  • How to link two .java files together?

    hello everybody,
    is it possible to link two or more .java files together? I mean is if I have 3 .java files. (a.java, b.java, c.java) then I have 3 .class files too. How do I use the method in other .java files. For example :
    public a extends Applet {
    // call b.class
    b();
    public b extends Applet implements ActionListener {
    void title1() {
    How to call the b.class? How to call the title1() method?
    Is it related to JAR or package??
    Thanks for helping me. v(^_^)v

    O.K, you do not link ".java" files together.
    You compile them into class files and they can create new instances of each other and and access their variables and work together.
    I recommend "Sam's Teach Yourself Java in 21 Days".
    It will start you out with the basics.
    --Ian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  • How to link two header files so that it may be taken from the library ONLY

    Hi.
    I was able to compile and successfully execute a program earlier
    written in Oracle 7 (Solaris) Now in Oracle 10G (Linux). The only
    problem is that I have to include two header files
    sqlca.h and sqlda.h in the present working directory.How to enter them in the linking command so that I do not need to
    copy them everytime in the current working direcotry ?
    I have used the following commands :
    $ proc sample.pc
    $ cc -L$ORACLE_HOME/lib -L/usr/lib -lclntsh -o sample sample.c
    regds.
    J.S.S

    Use always -I option of the compiler to include all header file directories U wich to add. In this case no need to copy the files.

  • How do I dynamically load a SWF that was compiled from an Fla with a linked external class file

    I am dynamically loading external SWFs in a Main Fla in response to clicks on a menu.
    The loading code is standard and works fine for all of the SWFs except one. When I try to load it I get the following error:
    Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
    I am certain that the URL to the problem SWF is correct. The SWF itself doesn't load any other SWFs or images.
    The problem SWF is linked to an external class file and compiled with it.
    i.e. in the properties panel of the main timeline of the problem SWF's Fla I have entered the path to the external class.
    1. there is no problem compiling this SWF with the class (it works fine by itself)
    2. if I remove the external class from the properties panel and don't use it the resulting SWF imports without a problem into the Main Fla mentioned before
    So the problem seems to be the fact that the external class is linked in the properties panel. Is this a path problem?
    Would appreciate any suggestions,
    Thanks!

    despite what you say, that loaded swf most likely is loading something and that's the cause of the error.
    you could test that by putting the main swf's embedding html file in the same directory with problematic swf.  if the problem is as explained above, you'll have no problem when the main html is in the same directory with the loaded swf.

  • Two class files with $ on compile

    Hello friends, I have a simple java program, that consists of two classes, coded in the the same java file.
    One of hte classes extends Thread.
    When I compile the source file, I get one class file for the base class, and two for the other one - ClassName.class and ClassName$1.class.
    Why is the second one created?

    The ClassName$1.class is a class file for an anonymous inner class. You create them with code likebutton.addActionListener(new ActionListener() {
         actionPerformed(ActionEvent ae) {
              System.out.println("button was pressed");
    });This particular example is from the GUI world where event listeners are commonly created using anonymous inner classes. There's a separate file for it just because there's always exactly one class file for each class.

  • Link two XLF files

    Hello Experts
    Is it possible to link two different XLF files . What I have to do is Have a Master XLF file and call the subsequent XLF files from the master XLF file. If it is possible please some one Explain me how.
    Thank You

    Not XLF to XLF but you can link the two swf files.  See here:
    http://ryangoodman.net/blog/index.php/2006/12/15/passing_data_from_a_parent_to_child_swf
    Regards
    Charles

  • Passing variables and methods between two class files

    I created two simple programs to see what I can learn about how separate class files work together.
    There are two files, Alpha.java and Beta.java. Both are located in the same folder.
    Here�s Alpha.java:
    ********* Alpha.java *********
    public class Alpha {
    public int alphaInt;
    public void alphaMethod() {
    System.out.println("This is Alpha's alphaMethod.");
    ******** End Alpha **********
    Here�s Beta.java
    ******** Beta.java ***********
    public class Beta {
    public static void main() {
    Alpha a = new Alpha();
    a.alphaInt = 10;
    System.out.println(The value of alphaInt is " + a.alphaInt);
    a.alphaMethod();
    ******** End Beta ***********
    Alpha compiles fine. Beta does not compile and I get this error:
    �Exception in thread �main� java.lang.NoSuchMethodError: main�
    My first problem to solve is to get Beta to compile. After that I should be able to run it from the command line and get something like this as output:
    �The value of alphaInt is 10�
    �This is Alpha�s alphaMethod.�
    Would some kind people please help me with this?
    TIA,
    Logan

    That was easy, and it confirms what I thought should happen. Now for the real question:
    Alpha and Beta are servlets in a package called abClasses. Alpha starts out like this:
    package abClasses;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import java.util.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class Alpha extends HttpServlet {
    Beta is the same, except for the name of course.
    Alpha creates a Connection variable, and Beta is going to use it. But when I try to compile Alpha I get an error that says this:
    cannot resolve symbol
    symbol: class Alpha
    location: abClasses.Beta
    Alpha a = new Alpha();
    Any suggestions on why what we did in the simple Alpha and Beta programs won't work in the Alpha and Beta servlets?
    You are appreciated,
    Logan

  • Link two SWF file

    I have a slider control in 1.swf file and another slider controler in 2.swf . I want link these two sliders, 2nd one should respond to the 1st one .How to do that please help.........

    In what way are these two files implemented such that they both exist at the same time?

  • How to link two labview files

    Hi,
    I have got a file that generates a signal, i have to link the signal that is generated in the first file to the second one . can you please help me how to do this. awaiting for your reply.
    Solved!
    Go to Solution.

    Create a subvi of the vi that generates the signal and use it in the main vi (second one).

  • How do you link two Indesign Files

    I am creating an IPad App in InDesign, made up of 8 different InDesign Files. eg Wedding.indd, Travel.indd, Pricing.indd, Home.indd, etc.
    My aim is to link the Home Page to each of the other pages so that when a user taps  for example Wedding on the Home page it will take them to the Wedding Page and so on.
    I have used go to page with no luck and go to file again with no luck, can anyone out there help with this please?
    Thanking you in advance
    Barb

    See https://helpx.adobe.com/digital-publishing-suite/help/hyperlink-overlays.html#create_links _to_other_articles for instructions on how to do this.
    Neil

  • *Added* code to existing source file, compiled it, and class file shrunk

    Another newbie here. Fortunately, my classpath is ok, so I'm able to compile a .java file.
    I added one line of code (System.out.println) to write the value of a variable to a log. After compiling with javac, I noticed that the resulting [new] class file was smaller than the existing class file. I looked at each of the class files with Textpad. It's gibberish, but I quickly saw that a large block of code was missing in the new class file, even though the size of the source file had been increased.
    There is a difference, however, between how the two class files were created. The existing class file was compiled (along with many others) by exporting an .EAR file from a development environment (WSAD) to the WebSphere Administrator Console. Conversely, I am now compiling the same source file with javac on my machine.
    I suspect that this is the reason why I can add code to a .java file, compile it, and have the resulting class file actually lose code. Even if I am correct, I don't know what to do about it.
    Does anyone have an idea?
    Regards,
    Daniel T.

    Thank you both for your replies. I've read many posts over the past few months, and I know how important it is to provide as much info as possible, when asking a question here. That said, I have another tasty tidbit...
    After replacing the existing (larger) class file with the new (smaller) class file, my application now produces this:
    "*Error 500: LinkageError while defining class*..." [name of class]
    *"...(Unsupported major.minor version 50.0) This is often caused by having a class defined at multiple locations within the classloader hierarchy. Other potential causes include compiling against an older or newer version of the class that has an incompatible method signature. Dumping the current context classloader hierarchy: ==> indicates defining classloader ==>[0] com.ibm.ws.classloader.CompoundClassLoader@6bd156d5 Local ClassPath:"*
    ...[the entire classpath]...
    Original exception--- java.lang.UnsupportedClassVersionError:
    I'm guessing that my focus should mostly be on the 'Original exception', and maybe I need to revisit the JRE or JDK or JVM (these terms are somewhat nebulous to me, so please forgive me using them interchangeably) on my machine. For now, I'll just keep trying stuff. Thanks again for the replies!
    Regards,
    Daniel T.

  • .class Files with "$X" extensions

    Hi everybody,
    when I deploy my App, some confusing .class files are generated by my JDev (10.1.3.3) ...
    In my Project I declare a Class named
    - JClientDesktopManager.java
    This is compiled to two .class files:
    - JClientDesktopManager.class     
    - JClientDesktopManager$1.class
    Whats that strange class with "$1"?
    Should I care about about it? - it seems randomly...

    Hi!
    Theses files house anonymous inner classes, a standard Java mechanism.
    Whenever you write something like:
    ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { <your code here> }};or
    JTable table = new JTable() { public boolean isEnabled() { <your code here> }};you create in fact new (anonymous) inner classes. These classes have no name (hence "anonymous"), they are just numbered.
    For more background you could just Google for "anonymous inner class".
    Sascha

  • Automatic copying of class file problem

    I am using Weblogic 4.5.1 server on NT.
              I have a JSP "main.jsp" in which I am importing a user defined class
              "com.vt.Attribute".
              The Jsp is getting compiled into a servlet in
              "weblogic\myserver\classfiles\jsp_servlet\_jsp" directory. Also the file
              "Attribute.class" is getting placed automatically in directory
              "weblogic\myserver\classfiles\com\vt". Because of this, I am getting a
              ClassCastException, since the serial ids of the two class files will be
              different.
              How can I prevent the automatic copying of the "Attribute.class" into
              "weblogic\myserver\classfiles\com\vt" directory.
              Regards.
              

    Remove the package statement in your source code.
              I think this could be the cause.
              Chandra
              "Raghav" <[email protected]> wrote in message
              news:[email protected]..
              > I am using Weblogic 4.5.1 server on NT.
              > I have a JSP "main.jsp" in which I am importing a user defined class
              > "com.vt.Attribute".
              >
              > The Jsp is getting compiled into a servlet in
              > "weblogic\myserver\classfiles\jsp_servlet\_jsp" directory. Also the file
              > "Attribute.class" is getting placed automatically in directory
              > "weblogic\myserver\classfiles\com\vt". Because of this, I am getting a
              > ClassCastException, since the serial ids of the two class files will be
              > different.
              >
              > How can I prevent the automatic copying of the "Attribute.class" into
              > "weblogic\myserver\classfiles\com\vt" directory.
              >
              > Regards.
              >
              >
              

  • Linking a class to a symbol

    I have a simple progress bar symbol (ProgBar) in the library of main.fla. If I don't define a class and allow Flash to assign a placeholder class of ProgBar, then the symbol displays ok using
    progBar = new ProgBar();
    addChild(progBar);
    If I define a class, even the basic empty version below, I get the following error:
    ReferenceError: Error #1056: Cannot create property percent_txt on ProgBar.
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at flash.display::MovieClip()
    Class code:
    package {
    import flash.display.*;
    import flash.text.*;
    public class ProgBar extends MovieClip {
      public function ProgBar(): void {
    percent_txt is a text field I've given an instance name to. If I delete the text field (or its instance name) the error changes to reference the next item in the symbol and so on until there are none left!
    What have I missed?

    Well, yes, I thought it was a great plan! As part of my AS3/OOP education I'm trying to design a progress bar symbol with an associated class file for use in various projects. So I have progBar.fla containing a symbol, progBarMC, linked to class file ProgBar.as (which currently only traces "ProgBar constructor" as each instance is created). To test this I have main.fla and its document class Main.as. I've dragged a copy of progBarMC into the library of main.fla. Main.as looks like this:
    package {
    import flash.display.MovieClip;
    import flash.text.*;
    public class Main extends MovieClip {
      var progBar:MovieClip;
      public function Main() {
       progBar = new ProgBar();
       addChild(progBar);
    This only seemed to work if the symbol files were in the same folder as main.fla, but I've fixed that now - I hadn't set a class path for the symbol files.
    Your question sort of implies that this might not be an ideal approach. Any advice gratefully received!

  • Tools for Comparing Java Class Files

    Are there any tools out there that can compare two .class files to see if they are the same ?? Please help.
    Janet

    In Windows there's the FC command that compares two files to see if they are identical. In Unix there is no doubt a similar command. Or you could write a small bit of Java code that reads the two class files and compares them byte by byte.

Maybe you are looking for

  • Using reader 11.0.06 to convert file to excel

    I'm somewhat reluctant to do this because I'm really out of my comfort zone with computer stuff but I need help.  I just downloaded reader 11.0.06 and converted a pdf file to excel.  The problem is that the info in excel is all down the left side and

  • How to change the incoming xml to a different namespace

    I have a xml file coming into XI (file ->XI)without namespace. I would like to change the root elment with ns tag add the namespace values with it. ie., Coming in as <Vendor> </Vendor> I would like to change it to <ns:Vendor xmlns:ns="urn:group01:leg

  • Text output from 11i Reports to Excel - bad Format

    Hi All, We have a report in Oracle Apps 11i(11.5.10) with Text as output format. We would like to open the file in Excel format. We have done the recommended setups from the metalink note ID 316752.1. Output is generated in Excel, but the format is n

  • LabVIEW Position in Bangalore, India

    We Are going through the second round of hiring to add to our existing team of LabVIEW Engineers who are based in Bangalore. The Job Details are as follows: Job Title: Systems Engineer (Test Software and Integration Group) or Senior Systems Engineer

  • Blocked Windows (Bizspark) keys

    I have some problems with Windows (Bizspark) keys. A few weeks ago I generated one key for Win 8, one for 7 and one for XP. Save these 3 keys I haven't generated any other keys for any other products and there are no other members registered in my Bi