Running 2 classes together

I have 2 classes that i want to run together. They both have
GUI components to run there separate methods. The code is long
so i've shown the stripped down basic idea below.
public class Class2 extends JFrame
     public Class2(String name)
            super(name);
          //Code for GUI
     public Class2()
          //Default constructor to access the class
     public void createPopupFrame()
          //code to show the Internal Frame
          frame.show();
     public static void main(String[] args)
          //Runs the GUI
          new Class2("Class2");
} i want to call the method for the internal Frame ( createPopupFrame() ) from Class1
while Class2 is running and therefore popUp that frame in class2.
class Class1 extends JFrame
     //Various GUI components
       public Class1(String name)
             super(name);
            //Code for GUI
            //Button to call the method callPopUP()
       public Class1()
            //Default constructor to access the class
     public void callPopUP()
          Class2 dis = new Class2();
          dis.createPopupFrame();
     public static void main(String[] args)
          //Runs the GUI
          new Class1("Class1");
     }//end main
}I'm having trouble implementing this in java. I searched around the api
and the forums and found some stuff about Runnable interface but i'm not really
any the wiser. I've tested the createPopupFrame() method and i works fine from within
class2.
When i call it from class1 while class2 is running i get a NullPointerException. Although
i expected this because i knew, that would just be too easy.
Any help appreciated.

Line 171 in class2I assumed line 171 referenced an object created
somewhere in line 170.I believe this to be an incorrect assumption.
and line 7 in class1I fail to see the null reference here by virtue of
line 6.Typically , a stack trace shows a call sequence. Since line 7 calls the method containing line 171, if frame is null, the NPE stack sequence would show:
NPE in line 171
called from line 7
OP. Try the following:
public void createPopupFrame()
    //code to show the Internal Frame
    if ( frame != null )
        frame.show();
    else
        System.out.println( "The frame object has not been instantiated." );
}Good luck.
� {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Running Class in package?

    I have problem running class in package. What do I write (win) to make the class in a packege run? If I remove it from the package I just write: java MyClass.

    If it is in package com.bananaco, for example, then at
    the command line you must type
    java com/bananaco/MyClassI'd refrain from calling it that way, as it leads to confusion.
    The standard way is to call it fully qualified
    java -cp <classpath> com.bananaco.MyClass
    under any JAVA release with the classpath set appropriately (rename <classpath> with yout path to directory where com is located in exmpale above).
    Take in mind that the directory structure should reflect the package structure (having MyClass.class under com/banaco in the class path)
    Oliver
    >
    That works for Java 2, but I sort of recall that for
    Java 1 you had to use
    java com.bananaco.MyClass
    instead. So try both. And if you get NoClassDefFound
    error, remember that the package has to be in
    your classpath, not the class.

  • Running class files from the windows command line...

    Hello Everyone,
    My instructor showed us a way to run class files from the windows command line. However every time I try to run the class file from the command line using a command like: java CruiseHelper.class
    I get an error that states "Exception in thread "main" java.lang.NoClassDefFoundError: CruiseHelper/class"

    Hello Everyone,
    My instructor showed us a way to run class files from
    the windows command line. However every time I try
    to run the class file from the command line using a
    command like: java CruiseHelper.class
    I get an error that states "Exception in thread
    "main" java.lang.NoClassDefFoundError:
    CruiseHelper/class"Classes are not file names. You don't have a class named "CruiseHelper.class", that's a file name. The class name is just CruiseHelper (if you have no package statement in it).
    So,
    java -classpath . CruiseHelper

  • Using CSS class together with CSS Rule

    Hi,
    I design my web site in Dreamweaver and then use Web
    Developer 2005 Express for the dynamic stuff. I amalgamate all the
    work I have done in Dreamweaver into 2005 Express. However with the
    new server side controls I do not know how to add a CSS class
    together with a CSS rule.
    In the normal client side control in Dreamweaver I have -
    <input name="txtPassword" type="password" class="Input"
    id="SpacerBottom" />
    In the server side controls the ID keyword is used now -
    <asp:TextBox ID="txtPassword" runat="server"
    Style="z-index: 107" CssClass="Input" ></asp:TextBox>
    I have tried to use the name="txtPassword", but it ignores
    this.
    I would really like to know how I can use a class and an id
    selector with the new server side controls and would really
    appreciate some help on this.
    Many thanks,
    Polly Anna

    the explicit " match-any" will do just that.So, a nested ACL can be configured for multiple criteria.
    The alternate is a "match-all" where all nested options in your acl MUST be met. Hope this helps.
    T

  • How to run .class file and .jar file in jdev9i

    I want to run .class file and .jar file in jdev9i,what should I do?
    Also,I want to generate .class file and .jar file in jdev9i,what should i do?

    Add the .class file containing the public static void main(...) method to the project by clicking on the + toolbar button in the navigator, open the project properties and properly set the additional classpath then right click on the .class in the navigator and say run. It should work, I've just tried it.
    Doesn't work for a .jar yet, in JDeveloper 9.0.3 it works both for .class and .jar
    Michel

  • Linking classes together

    hi, do u guys know of any tutorials about linking two or more classes together?
    i need to learn anything and everything about it.
    thx,
    gildan2020

    class A
        public static void main(String[] args)
            // uses static PrintStream object in System class and
            // calls the println() method on that PrintStream object.
            System.out.println("Hello World");
    }http://java.sun.com/docs/books/tutorial/
    http://java.sun.com/learning/new2java/index.html
    http://javaalmanac.com
    http://www.jguru.com
    http://www.javaranch.com
    Bruce Eckel's Thinking in Java
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java

  • Using two versions of the one class together?? (I think)

    Hi, see the following small program, where the user can enter an int, and the program draws that amount of lines, joined together at a centre point. The user can then move these lines around the centre by dragging the red dot at the end of the lines.
    Anyway, what I want to be able to do, is have two different versions of this program running side by side, independently of each other. (ie one might have 4 lines, the other have 3). Each one, would also be able to read data from each other.
    Is this possible?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Lines4 extends JFrame implements MouseListener, MouseMotionListener {
    private int startx = 200;
    private int starty = 200;
    private JLabel statusBar;
    private Road roads[];
    private static final int roadLength = 100;
    private static final int circleRadius = 4;
    private Road movingRoad;
    public Lines4() {
    super("Lines4");
    String ret = JOptionPane.showInputDialog("How many roads are there?");
    int numPoints = Integer.parseInt( ret );
    double factor = 2.0 * Math.PI / ( numPoints ) ;
    roads = new Road[numPoints];
    for (int i=0; i<numPoints; i++){
    int x = (int)( roadLength * Math.cos( factor * i ) );
    int y = (int)( roadLength * Math.sin( factor * i ) );
    roads[i] = new Road( i, startx, starty, circleRadius, startx+x, starty+y );
    addMouseListener(this);
    addMouseMotionListener(this);
    statusBar = new JLabel();
    getContentPane().add(statusBar, BorderLayout.SOUTH);
    public void paint( Graphics g ) {
    g.clearRect( 0, 0, getWidth(), getHeight() );
    for (int i=0; i<roads.length; i++) {
    roads.draw( g );
    // MouseListener Event Handlers
    public void mouseClicked( MouseEvent e ){
    statusBar.setText( "Clicked at [" + e.getX() +
    ", " + e.getY() + "]" );
    public void mousePressed( MouseEvent e ){
    statusBar.setText( "Pressed at [" + e.getX() +
    ", " + e.getY() + "]" );
    for (int i=0; i<roads.length; i++) {
    if ( roads[i].onCircle( e.getX(), e.getY() ) ) {
    movingRoad = roads[i];
    public void mouseReleased( MouseEvent e ){
    statusBar.setText( "Released at [" + e.getX() + ", " + e.getY() + "]" );
    movingRoad = null;
    public void mouseEntered( MouseEvent e ){
    statusBar.setText( "Mouse in window" );
    public void mouseExited( MouseEvent e ){
    statusBar.setText( "Mouse outside window" );
    // MouseMotionListener event handlers
    public void mouseDragged( MouseEvent e ){
    statusBar.setText( "Dragged at [" + e.getX() +
    ", " + e.getY() + "]" );
    if ( movingRoad != null ) {
    movingRoad.x = e.getX();
    movingRoad.y = e.getY();
    repaint();
    public void mouseMoved( MouseEvent e ) {
    statusBar.setText( "Moved at [" + e.getX() +
    ", " + e.getY() + "]" );
    public static void main( String args[] ) {
    Lines4 app = new Lines4();
    app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    app.setSize( 400, 400 );
    app.setVisible( true );

    You need to be very careful which project you open in which version.
    For 2014 make sure its on 2014.1 build 81.

  • Bringing Classes Together

    Hi I've been working on a calculator that now writes to file, and can activated from a main menu. I got the two to work together by extending the main menu to the calculator and simply running the method where it was needed.
    Then I wanted to veiw the file. So I put together a program that would read and display the text when run, But I mentioned earlier that I extended the Calculator to the MainMenu to get them to work together, now how am supposed to extend the FileReader as well?
    I have three classes:
    A main Menu class. - asks user to input 1 for calculator, or 2 to veiw file. So if(input==1); run the method, which is inside the calculator class.
    if(input==2); I want to view the file.
    I have a lonely FileReader class, I've tried extending the MainMenu to it, but that hasn't worked. So I need help with using the method that's inside the FileReader class, in my MainMenu class.
    This might be an easy one... too easy? Any help would really be appriecated. I can post the code for any or all of the classes if it helps.

    This is the code for the main menu. Before I introduced the second option (view file), the classes worked together without problems.
    it was originally:
    class Menu_RunThis extends CalcSalesTax {I extended the CalcSalesTax class so that I could use the method in CalcSalesTax "salesTax()"
    But now that I have another class with a method in it which I would like to use, how do I use it?
    (See method getContents)
    This is the broken code... of the MainMenu*:*
    import java.io.*;
    import java.util.*;
    class Menu_RunThis    {
    public static ReadLog getContents = new getContents;
    public static CalcSakesTax salesTax = new salesTax;
    public static void main(String[] args)throws java.io.IOException {
    System.out.println("Instructions:");
    System.out.println("**************");
    System.out.println("Press '1' to calculate sales tax, specify the number of items you intend to\r\ncalculate, and their prices. This calculator assumes that sales tax is equal to 6.5 %.\r\nThe information you provide/recieve is stored in a text-file for your convience.");
    System.out.println("");
    System.out.println("Please Select:");
    System.out.println("1: to Calculate Tax");
    System.out.println("2: view Log File");
    System.out.println("or");
    System.out.println("0: to Exit");
    int val = 3;
    while (val != 0)
    Scanner input = new Scanner(System.in);
    val = input.nextInt();
    if (val == 0) return;
    else if (val == 1) salesTax(); //SalesTax method is called
    else if (val == 2) subMenu();
    else {System.out.println("Please Select:");
    System.out.println("1: to Calculate Tax");
    System.out.println("or");
    System.out.println("0: to Exit");}}
    public static void subMenu(){
    System.out.println("Please Select:");
    System.out.println("1: To view the Log file");
    System.out.println("or");
    System.out.println("0: to Exit");
    int val = 3;
    while (val != 0)
    Scanner input = new Scanner(System.in);
    val = input.nextInt();
    if (val == 0) return;
    else if (val == 1) getContents(); //getContents method is called
    else {
    System.out.println("Please Select:");
    System.out.println("1: To view the Log file");
    System.out.println("or");
    System.out.println("0: to Exit");
    }}Edited by: tark_theshark on Nov 26, 2007 10:58 PM

  • Tie classes together

    I want to include the shapes (my inventory logo) on the next button frame, which should display the next item on the array list (I havent gotten to the array yet). Both of these classes run when apart, but do not work together. Help?Advice?(Please dont tell me to drop the class)
    Only one more week to go in this class (and Im pretty sure I will pass) whew...i know yall will be happy when I go away lol
         import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class InventoryGUI1 extends JFrame
                              implements ActionListener {
        JTextField input;
          JTextField output;
          JButton next;
          Container c;
    public InventoryGUI1 (){
        super ("My Inventory GUI");
          input = new JTextField (15);
          output = new JTextField (15);
          output.setEditable(false);
          next = new JButton ("next->");
          next.addActionListener (this);
          c = getContentPane ();
          c.setLayout (new FlowLayout());
          c.add (input);
          c.add (next);
          c.add (output);
          setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          setSize (400,300);
    public void actionPerformed (ActionEvent ev) {
        String userInput = input.getText ();
          output.setText (userInput);
          input.selectAll();
    public static void main (String args []) {
    InventoryGUI1 app = new InventoryGUI1 ();
    app.setVisible (true);
    SwingDrawInner app = new SwingDrawInner ();
    app.setVisible (true);
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class SwingDrawInner extends JFrame {
    Container fc;
    DrawingSurface ds;
    JLabel lbl;
    public SwingDrawInner() {
    super("A Swing Drawing Application");
    ds = new DrawingSurface();
    lbl = new JLabel("Stephanie's Music Inventory");
    fc = getContentPane();
    fc.setLayout(new FlowLayout());
    fc.add(ds);
    fc.add(lbl);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(300,200); }
    class DrawingSurface extends JPanel {
    Dimension preferredSize = new Dimension(300,100);
    public DrawingSurface() {
    super();
    public Dimension getPreferredSize() {
    return preferredSize;
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawOval(20, 20, 80, 60 );
    g.drawRect(110, 20, 80, 60);
    g.drawOval(200, 20, 80, 60);
    public static void main(String args[]) {
    SwingDrawInner app = new SwingDrawInner();
    app.setVisible(true);
    public static void main (String args []) {
    InventoryGUI1 app = new InventoryGUI1 ();
    app.setVisible (true);
    SwingDrawInner app = new SwingDrawInner ();
    app.setVisible (true);
                              

    Additionally
    -- Learn to format your code according to the conventions. It's difficult to read code that's all jammed up together.
    [http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html]
    -- For anything more complicated than the most basic GUIs, you need to show the GUI on the EDT. For that, your main method in the code I posted above would look like:    public static void main (String args []) {
            SwingUtilities.invokeLater (new Runnable () {
                public void run () {
                    InventoryGUI1 app = new InventoryGUI1 ();
                    app.setVisible (true);
                    SwingDrawInner app1 = new SwingDrawInner ();
                    app1.setVisible (true);
        }db

  • How to run class files in a jar independently.

    Hello all
    I have a java file which use an API.jar file which is an API file of some other application of mine.This file form a sought of client for that application.Now i want to run this file from command line which is giving NoClassDefFoundError exception.This exception is because of the dependency over API.jar.I dont want to pack this single file into a jar and then run that jar since it only makes a simple task complicated and makes a simple class look like a big application.Can anybody tell me the solution to it?
    Regards,
    Mansi

    MansiSachar wrote:
    I am working on WindowsXP and the command u just sent is again giving the same exception.The exception is :
    Exception in thread "main" java.lang.NoClassDefFoundError: ûcp
    Caused by: java.lang.ClassNotFoundException: ûcp
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    I think the problem can also be the placement of the dependant jars.do i need to keep them in "bin" folder?I am assuming that in the error message, it says "-cp" not "ûcp" Can you confirm that you entered the command as posted? Because it looks like java.exe sees the -cp as the class to execute instead of the classpath option.
    Try using -classpath instead of -cp. What version of java are you using? (java -version should give you the version).
    If the jars are in the current directory, the placement of the jar files is correct.

  • Can a signed applet run classes from disk?

    Hi all,
    I have a signed applet jar and a signed jar file somewhere on disk (I can ensure the jar file is available on client's machine before i run the applet). My applet doesn't let me have file io access from the classes in the jar file on disk. It gives the following exception:
    java.security.AccessControlException: access denied (java.io.FilePermission C:\test.jar read)
    However I do have file io access from classes in the applet jar itself. Both the jar files are signed.
    Is there any way to get around the plug-in security in this case?
    Using installed extension (jar/lib/ext) is not an option, unfortunately.
    Any help will be appreciated.
    -Jas

    Is it not the same problem of JavaScript which calls Java ?
    Harmemejer posted : http://forum.java.sun.com/thread.jsp?forum=63&thread=524815 (second post) ???
    Hope it helps
    Rafax.

  • Call function inside running class

    Hey All,
    i have a two question in classes.
    1- i have class and i called its before and its running on runtime. i need to call function inside this class from another class, but without call the first one again, because if i called it, it will run default class function again
    is this doable ?
    2- What super() mean ?
    Thanks a lot.

    this is the default call, and when i call the method by this way its will run the default class function before call the method.
    here my example:
    i need to call checkboxes  function in ChannelsMain class without pass by the grey script.
    Note: the call_cb is working and the trace is working
    so i now the class is running, i need to call the checkboxes without ( var ci:YourClass = new YourClass(); )
    package com.link
         import fl.controls.CheckBox;
         import flash.events.*;
         public class ChannelsMain
              var cbLength:uint = Main.PV.channel_id.length;
              public function ChannelsMain()
                   // constructor code
                   for (var i:int = 0; i < cbLength; i++)
                        var cb:CheckBox = new CheckBox;
                        cb.name = Main.PV.channel_id[i];
                        cb.label = Main.PV.channel_name[i];
                        cb.x = 50;
                        cb.y = 50 + i * 30;
                        cb.addEventListener(Event.CHANGE,call_cb);
                        Main.MS.addChild(cb);
                        //call xml function
                        if(i == cbLength - 1)
                             new ChannelsXML();
              private function call_cb(evt:Event)
                   trace(evt.currentTarget.name,evt.currentTarget.selected);
              public function checkboxes(evt)
                   trace(evt);

  • Running .CLASS file in Java JDK1.3.1_19

    Hello
    i am an old java programmer. but stopped for a while... so i guess im a bit rusy at it...
    anyway...
    i installed jdk1.3.1_19 on my pc and did everything as they asked for in the installation but i get an error wen i run the .CLASS file
    the error i get is:
    "exception in thread 'main' java.lang.NoClassDefFoundError: C:\jexamples\Welcome1"
    i read a documentation abt some CLASSPATH... which im kinda confused abt... how do i set that? and wat do i set it as?...
    Thanx for the help in advance!

    i am an old java programmer. but stopped for a
    while... so i guess im a bit rusy at it...
    anyway...
    i installed jdk1.3.1_19 on my pc Why did you install an old version instead of the latest version?
    and did everything
    as they asked for in the installation but i get an
    error wen i run the .CLASS file
    the error i get is:
    "exception in thread 'main'
    java.lang.NoClassDefFoundError:
    C:\jexamples\Welcome1"
    i read a documentation abt some CLASSPATH... which im
    kinda confused abt... how do i set that? and wat do i
    set it as?...Do not set or use the CLASSPATH environment variable. Instead use the -classpath option when compiling or running your programs. Otherwise, you'll never figure out what's going on.
    When asking about compiling problems, you need to post:
    1) The path to all the files used in your program
    2) The prompt where you entered the commmand
    3) The actual command you entered

  • Running  .class file from autoexec.bat (in Windows Xp environment)

    How to run a .class file from autoexec.bat file. I have WinXP installed on my PC. I tried the solution given by Forum memebers but they didn't work.
    after setting the classpath
    i wrote
    java -cp simple in autoexec.bat , but results were not satisfactory.

    What does "not satisfactory" mean? If the commans works from any .bat file, it'll work from autoexec.bat, too.
    May I ask what you're trying to accomplish? I'm not sure whether XP dtill uses autoexec.bat for console initialization after all.

  • Error trying to run class

    Ok I have complied my Hello.java and have a Hello.class file. When I try and run it using Java Hello I get the following error.
    exception in thread "main" Java.Lang.NoClassDefFoundError:Hello

    When you type in "java Hello" the java.exe tries to find a file (or jar) that contains the Hello class. Then it tries to execute a method whose signature is:
    public static void main (String[] args)
    If it can't find the method, then it generates the error you posted. The method must be defined as static and void, must be named main (not Main, for example), and must use a String array as its single argument.

Maybe you are looking for

  • Lacie External Drive not recognized

    I just unpacked and turned on my new iMac Desktop. Then I plugged in my Lacie Desktop external drive (with all my files, iTunes and iPhoto data) to move all of my files. But the Lacie Drive doesn't show up anywhere on the iMac when plugged in. I've t

  • Where to package

    hi I'm gind of new to java and I was wondering after I add a file to a package with the "package" keyword where do I put it and do I compile it?

  • Activate acrobat 9 pro without internet connection

    I have installed a legal copy of acrobat 9 pro with key and wish to activate it without connecting the computer to the internet--How?

  • Asha 201

    Ok, so every time I go into my music, it comes up saying 'Searching for updates'. Ok so it had previously done this a few times before, so I wasn't overlly concerned. Until, when the loading thing came up and it went to 10% and then it all went black

  • 11.5.9 with win 2000 hangs during statspack

    Dear All, I started statspack, upon starting of SQL> @spcreate.sql Oracle application hangs and users are unable to work, then i restarted the serviecs, now its working fine but it is happend 2 times on the same point. spcreate.sql scripts completed