Implimenting GUI into main class

Hello all, I'm trying to figure out how to create a GUI for a program I'm writing.
Basically, the program I'm making allows a user to search through a list of movies that have been entered into a database (a textfile). The movie objects have a Title, Description, Genre, and a Rating.
I'm a little confused as to how I should set up all my code. I've written most of the background code to sort and search the movie objects, and I've also written most of the code to display the GUI. I just don't really know how to link them both.
Here's my question. I have a GUI class that currently has a main method, which calls run(), which then calls createAndShowGUI(), a method of the GUI class. Is this the right way to do things?
I also have a MovieSorter class, which creates an ArrayList of movieObjects, with the information taken from the text file. Unfortunatly, this too has a main method. So right now I can run the program from either class, to get the GUI to display, or to get the functional program to run. I don't know how to combine them.
I'm assuming I will have the main method be in the MovieSorter class, that will call the createAndShowGUI method, which will then display the GUI. Then the GUI listens for any input (buttons, etc) and calls the appropriate methods accordingly. Is this right?
I guess my main question is am I supposed to have a GUI object that I somehow put inside a JFrame (the GUI object being a JPanel or something)? I don't really know how the program is supposed to flow.
Thanks!
EDIT I can attach the code if you like, but it's a bit long.
Edited by: lifeismusic434 on Oct 22, 2008 6:57 PM

My take on something like this is that I look on the GUI as the View, and the non-GUI class as the Model. I suppose the program will be started by some Control object that will start up the GUI and start up the Model and link the two. Without more specifics, I'm afraid that that's the best that I can do. Hopefully someone else will give you more helpful advice.

Similar Messages

  • Refering FXML file element into Main class in Javafx

    Hi,
      Is it possible to refer FXML file elements or components  in main class in javafx?
       if possible then how?

    Typically you define a controller class to interact with the UI components. You can inject components into the controller by defining them as fields annotated with @FXML, and then define a fx:id attribute for those elements in the FXML file with attribute values matching the variable name in the controller class. There's a example in the "Adding Rows to the Table" section of the FXML tutorial.

  • Import a gui into a normal class

    ok well i am working on a project and for purposes of structured programming i am being asked by my people to import the gui into another class and in that other class i am supposed to define the event handler methods of my gui. i've never seen anything like it so could someone please show me an example plz
    import GUI.gui;
    // theotherclass.class
    gui mygui = new gui();
    // now how do i define the event handler functions for mygui from here?
    // is that even possible ?
    thanks for your help

    you cannot import gui . u can only make instance of GUI class the separation between GUI and another tasks it important , like in your case .
    suppose you have Applet
    public class WhiteBoard extends JApplet which has JButton and another components , ( static member )
    and has an instance of GUI class
    ShapeCanvas sc=new ShapeCanvas();
    public class ShapeCanvas extends JPanel
                         implements ItemListener,ActionListener, MouseListener, MouseMotionListenerand every JButton component ( in applet class ) has an addActionListener for this instance , or you can in GUI Class to call static members in Applet class and addActionListener(this) for them

  • Could not find the main class JRE 1.6 only with console program into Contro

    Hi,
    I want replace JRE1.5-11 with JRE 1.6.
    Applet is running correctly with JRE 1.6.
    But when i want launching Java program located into "Parameters/Control Panel"
    I have following error message "Could not find the main class JRE 1.6 "
    Regards
    Philippe

    i wouldn't report a nullpointer to sun unless you're fairly confident there's some sort of bug. if main() can't be found it sounds to me like a config issue. if nullpointer, sounds like a code issue. post the code if you want, but i don't think sun will help you debug this.

  • ClassNotFoundException on main class when no network access

    While testing that my Webstart application can run Offline, I ran into the following problem:
    [Setup]
    Using Webstart 1.6.0_01
    Using JRE 1.5.0_07
    [Steps to reproduce]
    1-While having access to network, download MEdit Webstart application from server
    => MEdit application is properly cached and because of desktop integration parameters, icon is added to desktop
    => MEdit application starts properly
    2- Close MEdit application and unplug network cable
    3- Double-click on icon on desktop (or go through Control Panel -> Java console) and start MEdit
    => This time MEdit does not start properly and instead, I'm having the following ClassNotFoundException:
    java.lang.ClassNotFoundException: com.miranda.medit.MEdit
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
         at com.sun.javaws.Launcher.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    I checked my jnlp file, but I haven't find any wrong. Does any one have a clue what could be causing the problem? I tried the steps above using demo applications and it I am not having any problem. Thus for sure there something wrong with my .jnlp file or the application itself.
    Here is a copy of the .jnlp file:
    <jnlp href="MEdit-Layout-red.jnlp" spec="1.0+" codebase="http://ca-ops-build1/projects/MEdit/multiproject/MEdit-Layout/release-red/jnlp">
    <information>
    <title>Miranda Editor Layout Project</title>
    <vendor>Miranda technologies</vendor>
    <homepage href="index.html"> </homepage>
    <description>
    Main module that is to be used for creation and modification of various layouts for different monitoring products of Miranda.
    </description>
    <description kind="short">The Layout Edition part of MEdit</description>
    <offline-allowed/>
    </information>
         <security>
    <all-permissions> </all-permissions>
    </security>
         <resources>
    <j2se version="1.5+" max-heap-size="256m" initial-heap-size="32m"> </j2se>
    <jar main="true" href="MEdit-Layout-1.0-SNAPSHOT.jar"> </jar>
    <jar href="junit-3.8.1.jar"> </jar>
    <jar href="batik-awt-util-1.6.jar"> </jar>
    <jar href="batik-dom-1.6.jar"> </jar>
    <jar href="batik-ext-1.6.jar"> </jar>
    <jar href="batik-svg-dom-1.6.jar"> </jar>
    <jar href="batik-svggen-1.6.jar"> </jar>
    <jar href="batik-util-1.6.jar"> </jar>
    <jar href="batik-xml-1.6.jar"> </jar>
    <jar href="itext-1.02b.jar"> </jar>
    <jar href="looks-1.3.1.jar"> </jar>
    <jar href="bsh-2.0b2.jar"> </jar>
    <jar href="epsgraphics-2005.04.03.jar"> </jar>
    <jar href="l2fprod-common-all-20051211.jar"> </jar>
    <jar href="jgraph-5.7.4.4.jar"> </jar>
    <jar href="jgraphlayout-1.2.2.jar"> </jar>
    <jar href="jgraphpad-6.0.1.2.jar"> </jar>
    <jar href="js-1.6R2-wo-optimizer.jar"> </jar>
    <jar href="commons-beanutils-1.7.0.jar"> </jar>
    <jar href="commons-collections-3.1.jar"> </jar>
    <jar href="commons-logging-1.0.3.jar"> </jar>
    <jar href="commons-configuration-1.1.jar"> </jar>
    <jar href="commons-pool-1.2.jar"> </jar>
    <jar href="commons-digester-1.6.jar"> </jar>
    <jar href="commons-betwixt-0.7.jar"> </jar>
    <jar href="log4j-1.2.8.jar"> </jar>
    <jar href="foxtrot-2.0.jar"> </jar>
    <jar href="commons-lang-2.1.jar"> </jar>
    <jar href="icontrolweb-app.jar"> </jar>
    <jar href="gsm-app.jar"> </jar>
    <jar href="gsm-dl.jar"> </jar>
    <jar href="gsm-common.jar"> </jar>
    <jar href="gsm-client.jar"> </jar>
    <jar href="miranda-miro-1.0-SNAPSHOT.jar"> </jar>
    <jar href="miranda-riverdance-1.0-SNAPSHOT.jar"> </jar>
    <jar href="miranda-commons-1.0-SNAPSHOT.jar"> </jar>
    <jar href="miranda-store-1.0-SNAPSHOT.jar"> </jar>
    <jar href="monako-data-1.0-SNAPSHOT.jar"> </jar>
    <jar href="monako-dsi-1.0-SNAPSHOT.jar"> </jar>
    <jar href="monako-config-1.0-SNAPSHOT.jar"> </jar>
    <jar href="monako-command-1.0-SNAPSHOT.jar"> </jar>
    <jar href="monako-dao-1.0-SNAPSHOT.jar"> </jar>
    <jar href="icontrol-widget-1.0-SNAPSHOT.jar"> </jar>
    <jar href="monako-sam-1.0-SNAPSHOT.jar"> </jar>
    <jar href="monako-resources-1.0-SNAPSHOT.jar"> </jar>
    <jar href="adapter-gsmclient-1.0-SNAPSHOT.jar"> </jar>
    <jar href="adapters-generic-1.0-SNAPSHOT.jar"> </jar>
    <jar href="mtfc-tools.jar"> </jar>
    <jar href="mtfc-common.jar"> </jar>
    <jar href="adapter-gsmservice-1.0-SNAPSHOT.jar"> </jar>
    <jar href="miranda-agent-router-1.0-SNAPSHOT.jar"> </jar>
    <jar href="router-common.jar"> </jar>
    <jar href="router-clients.jar"> </jar>
    <jar href="router-service.jar"> </jar>
    <jar href="router-gui.jar"> </jar>
    <jar href="router-plaf.jar"> </jar>
    <jar href="router-util.jar"> </jar>
    <jar href="icr_network.jar"> </jar>
    <jar href="icr_datatek.jar"> </jar>
    <jar href="icr_digipath.jar"> </jar>
    <jar href="icr_dummy.jar"> </jar>
    <jar href="icr_gvg7000.jar"> </jar>
    <jar href="icr_leitch.jar"> </jar>
    <jar href="icr_matrixhub.jar"> </jar>
    <jar href="icr_nv9000.jar"> </jar>
    <jar href="icr_pesa.jar"> </jar>
    <jar href="icr_pesausp.jar"> </jar>
    <jar href="icr_philips.jar"> </jar>
    <jar href="icr_probelSWP08.jar"> </jar>
    <jar href="icr_sonyhkspc.jar"> </jar>
    <jar href="icr_utahpl160.jar"> </jar>
    <jar href="icr_utahrcp1.jar"> </jar>
    <jar href="xmldb-api-20021118.jar"> </jar>
    <jar href="jug-2.0.0.jar"> </jar>
    <jar href="mtfc-service.jar"> </jar>
    <jar href="miranda-util.jar"> </jar>
    <jar href="mtfc-log.jar"> </jar>
    <jar href="mtfc-api.jar"> </jar>
    <jar href="mtfc-gui.jar"> </jar>
    <jar href="mtfc-beans-images.jar"> </jar>
    <jar href="mtfc-beans.jar"> </jar>
    <jar href="mtfc-panels.jar"> </jar>
    <jar href="snmp-plugin.jar"> </jar>
    <jar href="icontrol-scripting.jar"> </jar>
    <jar href="icontrolweb-images.jar"> </jar>
    <jar href="mmp_core.jar"> </jar>
    <jar href="asi-client.jar"> </jar>
    <jar href="asi-shared.jar"> </jar>
    <jar href="navigator-app.jar"> </jar>
    <jar href="streaming-media.jar"> </jar>
    <jar href="streaming-services.jar"> </jar>
    <jar href="streaming_tools.jar"> </jar>
    <jar href="streaming-media-linux.jar"> </jar>
    <jar href="streaming-media-windows.jar"> </jar>
    <jar href="jini-core.jar"> </jar>
    <jar href="norm.jar"> </jar>
    <jar href="jini-ext.jar"> </jar>
    <jar href="reggie.jar"> </jar>
    <jar href="jini-serviceui.jar"> </jar>
    <jar href="sun-util.jar"> </jar>
    <jar href="xmldb-common-20021220.jar"> </jar>
    <jar href="xmlrpc-1.1.jar"> </jar>
    <jar href="xercesImpl-2.6.0.jar"> </jar>
    <jar href="xalan-2.6.0.jar"> </jar>
    <jar href="xml-apis-1.0.b2.jar"> </jar>
    <jar href="xindice-1.1b3.jar"> </jar>
    <jar href="beandt-4.0.jar"> </jar>
    <jar href="jbcl-4.0.jar"> </jar>
    <property name="java.protocol.handler.pkgs" value="com.miranda.monako.dao.url.protocol"> </property>
    <property name="java.content.handler.pkgs" value="com.miranda.monako.dao.url.content"> </property>
    </resources>
    <application-desc main-class="com.miranda.medit.MEdit"> </application-desc>
    </jnlp>

    Ok I found the cause for the problem. It has to do with java.protocol.handler.pkgs in .jnlp file. Webstart uses that property and set it with 'com.sun.javaws.net.protocol|com.sun.deploy.net.protocol'. To fix the bug, I must make sure I append these two protocol handlers, as shown here:
    <property name="java.protocol.handler.pkgs" value="com.miranda.monako.dao.url.protocol|com.sun.javaws.net.protocol|com.sun.deploy.net.protocol">

  • How to manage over 200 main classes effectively?

    Where can I found some experience about a big System?
    What's a main class looks alike?
    I got a GUI--subGui--sub-subGUI----...
    and configuration--subconfiguration--subsubconfiguraiton...
    and others.
    How do I connect them together?

    The first thing to do is look at whether or not you actually need the 200+ classes ? Don't worry of the answer is yes. See if you cut down on the number of classes - there may already be standard classes available.
    That should leave you a smaller number of classes. The short answer to your questions is packages. Group the classes into several chunks of logical component or layers. There should be commonalities between the different views and configurations which lend towards a logical partitioning.
    You may want to look at the Struts architecture for guides towards a cohesive web-tier design. Although targeted towards the JSP-Servlet technologies, the Model-View-Controller paradigm applies to the your GUI app.

  • Could not find main class. Program will now exit. *SIGH*.....

    At first I thought it was just my own programs that I created with netbeans that had this problem; however, even the demo programs under the sdk folder give me this problem when i try to run them. Virtual Machine Loader will just come up with pop up saying "Could not find the main class. Program will not exit"
    I am a fairly competent programmer, not new to java. But I am new to guis in java, and using netbeans to create them. The program I am creating gives me this error with javaw and with java it will tell me NoClassDef for grouplayout. I checked the manifest file it looks alright:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.0
    Created-By: 10.0-b19 (Sun Microsystems Inc.)
    Main-Class: desktopapplication2.DesktopApplication2
    Class-Path: lib/appframework-1.0.3.jar lib/swing-worker-1.1.jar lib/swing-layout-1.0.1.jar lib/ant-swing.jar lib/SwingSet2.jar lib/swing-layout-1.0.3.jar
    X-COMMENT: Main-Class will be added automatically by build
    }(brackets not included)
    I am sort of lost.... Do I need to install ant separately?
    I feel like there may be some classpath issues?
    I have java 1.6 update 4 and netbeans 6.0
    I am completely lost I have been working on fixing this for the past 2 or 3 days now, and reading up all the information.
    Note: This is just a standard desktop application.
    Also I just thought of something. If I have install the development kit do I also need to install the framework or whatever for 6.0 separately? Meaning installing the latest version of jvm. Sorry if this isn't clear i forgot what it is called.
    Sorry if this sounds like a beginner question or something, but I am going crazy. If i am having this much trouble running my own program i really hope distributing files won't be this much of a nightmare....

    Please become familar with resources at the NetBeans site. There are tutorials and FAQs that cover usage of NB, and how to do things like you're asking.
    See my reply in this thread for more information
    http://forum.java.sun.com/thread.jspa?threadID=5270931&tstart=0

  • Jar file could not find main class.. I cant see why?

    I have read loads of tutorials on this and it should be very straight forward but i STILL cant make a working jar file of my program.. please see if you can see anything wrong with what im doing..
    my program is one .java file that compiles perfectly, and is runnable both through eclipse and by using the command prompt.. i made a jar file using both eclipse and the command prompt, and neither worked.. every time i run it by double clicking it i get the error "could not find main class, program will exit". here is the contents of my jar:
    CorePackage\IPEmailer.class
    CorePackage\IPEmailer$1.class
    CorePackage\IPEmailer$SMTPAuthenticator.class
    META-INF\MANIFEST.MF
    the MANIFEST.MF file contains:
    Manifest-Version: 1.0
    Class-path: .
    Created-By: 1.6.0_02 (Sun Microsystems Inc.)
    Main-Class: CorePackage.IPEmailer
    (yes there is a blank line at the end)
    the class mentioned in 'Main-Class' has a main method that looks like this:
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new IPEmailer();
    }the program uses 2 external jar files:
    activation.jar
    mail.jar
    and reads a file called:
    ipemailer.ini
    and writes a file called:
    ip.txt
    the program has no GUI and is intended to run 'silently' in the background
    please help me understand what is wrong with this

    package CorePackage;
    import javax.mail.*;
    import javax.mail.Authenticator;
    import javax.mail.PasswordAuthentication;
    import javax.mail.internet.*;
    import java.util.*;
    import java.io.*;
    import java.net.*;
    public class IPEmailer implements Runnable{
          * @param args
         String recipientsinput[]={""};
         String subject;
         String body;
         String server;
         String user;
         String pass;
         String from;
         String urlString = "http://www.whatismyip.org";
         String currentIP;
         String ipFromFile;
         boolean webFailed;
         long interval = 900000; //15 mins
         long oldInterval;
         Thread t = new Thread(this);
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              new IPEmailer();
         public IPEmailer(){
                         ..........etccould the problem be that the class is a thread? i cant see why it would be, but ive never made a jar where the main class also 'implements runnable'

  • Can not start WebLogic in Eclipse. Error: "Could not find the main class."

    I have installed Eclipse 2.0 and WebLogic Server 6.1. and the WebLogc plug in from GENUITEC (and jdk1.3.1_04, on Win2K Server). After I have done the configuration, the WebLogic start/stop buttons are integried into the Eclipse Toolbar, but when I click on the start button to start Weblogic, it pops up a dialog box "Java Virtual Machine Launcher" with message: "Could not find the main class. Program will exit!"
    Starting WebLogc Server from the Start panel works fine.
    Does any one have seen this before or have a suggestion what I should do?
    Many many thanks in advance.
    Huan

    Weblogic must be started with a full JDK; otherwise
    JSPs and dynamic EJB stubs could not be deployed. The
    error message
    indicates you are attempting to use a JRE. Configure
    Eclipse JRE to point to a JDK. The product
    documentation will help you with this process. It does not work for me. :-(
    I have tried JDK 1.3.1 and 1.4.1: same result: I get a "Could not find the main class: Program will exit"
    For free expert support please consider contacting
    Genuitec at [email protected] If just want any
    answer ask a newsgroup.
    WayneI'll try the support at '[email protected]' :)
    Michel
    Michel Szybist
    [email protected]
    Fax: +33 (0)173729897
    SMS: http://www.szybist.net/

  • HOW TO SHOW JLABEL IN JDIALOG  WHILE MAIN CLASS IS SLEEPING? (CODE EDITED)

    I have done a code below and it is working but the only problem is when the main program start to sleep by use Thread.sleep(10000) for 10 secs and it will prompt out a JDialog contain JLabel inside it with message "Please wait.... program is sleeping.". And when the thread ends the JDialog will auto disappear and it back to the main program.
    I am using TimerTask to run the JDialog while the main class is sleeping.
    The problem is:
    When the JDialog appear, it doesn't show the component so I only be able to view the JDialog window without contain any component. I already use container to add the component into JDialog but it still doesn't show. I only be able to see the JDialog window contain empty component when the main window is sleeping.
    How to make the components also appear in the JDialog when the main program is sleeping?
    Below is the code pls have a try:
    public class testThread extends JFrame
    public static void main(String args[])
    new testThread();
    public testThread()
    * other code not related is here
    // WHEN USER PRESS startThreadBtn it will make the application sleep for 15 secs and pop out JDialog window contain JLabel msg wrote "Please wait... program is sleeping"
    JButton startThreadBtn = new JButton("Start Thread");
    startThreadBtn.addActionListener
    ( new ActionListener()
    public void actionPerformed(ActionEvent e)
    try{
    doTask a = new doTask();
    java.util.Timer thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0); // when this code executed, will pop out a JDialog containing JLabel message --> refer to class doTask
    Thread.sleep(10000);
    a.terminate()
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    infoDialog = new JDialog(true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    Why I can not show the JLabel inside the JDialog? The JDialog window is opened but it contain empty component.
    PLEASE HELP ME .... THIS IS VERY URGENT

    I have the complete code and it is working. I can posted it here but it will be longer thats the reason why i shortened the code in here and displaying the important information.
    The problem is the JDialog only will display the JLabel after the thread woke up. Thats mean it is too late for me to display the information. I need the JLabel containing the information to be displayed when the thread is sleeping....
    Below is the complete code:
    you can have a try to recompile it and u will understand what i mean. It is working and the only problem is JLabel component did not displayed in the JDialog.
    Just copy the whole code into the txt file and save as testThread.java and recompile it. Inside the code has one inner class extends TimerTask call "doTask"
    THE CODE START BELOW:
    import java.util.*;
    import java.lang.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class testThread extends JFrame
    public static java.util.Timer thisTimer;
    public static doTask a;
    public static testThread tT;
    public Container cMain;
    public Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    public JButton exitBtn;
    public JButton startThreadBtn;
    /** Creates a new instance of testThread */
    public static void main(String args[])
    new testThread();
    public testThread()
    //System.out.println("Start to call JDialog");
    tT = this;
    int realW = (int)screenSize.getWidth();
    int realH = (int)screenSize.getHeight();
    int mainW = 500;
    int mainH = 300;
    exitBtn = new JButton("EXIT");
    exitBtn.setBounds((int)((500-100)/2), (int)((300-50)/5), 100, 50);
    exitBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    startThreadBtn = new JButton("Start Thread");
    startThreadBtn.setBounds((int)((500-200)/2), (int)((300-50)/5*4), 200, 50);
    startThreadBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    try
    System.out.println("Start to call JDialog");
    a = new doTask();
    thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0);
    System.out.println("Thread start to sleep first 10 secs");
    Thread.sleep(10000);
    System.out.println("Thread start to sleep second 5 secs");
    Thread.sleep(5000);
    System.out.println("Thread Wake Up");
    a.terminate();
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    cMain = this.getContentPane();
    cMain.setLayout(null);
    cMain.add(exitBtn);
    cMain.add(startThreadBtn);
    setBounds((int)((realW-mainW)/2), (int)((realH-mainH)/2), mainW, mainH);
    setVisible(true);
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    System.out.println("TASK IS RUNNING");
    int screenWidth = (int)screenSize.getWidth();
    int screenHeight = (int)screenSize.getHeight();
    int w = 300;
    int h = 200;
    infoDialog = new JDialog(tT, true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setBounds((int)((screenWidth-w)/2), (int)((screenHeight-h)/2), w, h);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    this.cancel();
    ******************************************************************************************************************************************************************************************************************************************

  • How to restructure this code into separate classes?

    I have C# code that initializes a force feedback joystick and plays an effect file(vibrates the joystick). I have turn the console application into library
    code to make a dll so that I can use it in LabVIEW. 
    Right now all the code is written under one class, so went I put the dll in LabVIEW I can only select that one class. labVIEW guy told me that I need to
    restructure my C# code into separate classes. Each class that I want to access from LabVIEW needs to marked as public. Then I can instantiate that class in LabVIEW using a constructor, and call methods and set properties of that class using invoke nodes and
    property nodes.
    How can I do this correctly? I tried changing some of them into classes but doesn't work. Can you guys take a look at the code to see if it is even possible
    to break the code into separate classes? Also, if it is possible can you guide me, suggest some reading/video, etc.
    Thank you
    using System;
    using System.Drawing;
    using System.Collections;
    using System.Windows.Forms;
    using Microsoft.DirectX.DirectInput;
    namespace JoystickProject
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    private System.Windows.Forms.Label label1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    private Device device = null;
    private bool running = true;
    private ArrayList effectList = new ArrayList();
    private string joyState = "";
    public bool InitializeInput()
    // Create our joystick device
    foreach(DeviceInstance di in Manager.GetDevices(DeviceClass.GameControl,
    EnumDevicesFlags.AttachedOnly | EnumDevicesFlags.ForceFeeback))
    // Pick the first attached joystick we see
    device = new Device(di.InstanceGuid);
    break;
    if (device == null) // We couldn't find a joystick
    return false;
    device.SetDataFormat(DeviceDataFormat.Joystick);
    device.SetCooperativeLevel(this, CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Background);
    device.Properties.AxisModeAbsolute = true;
    device.Properties.AutoCenter = false;
    device.Acquire();
    // Enumerate any axes
    foreach(DeviceObjectInstance doi in device.Objects)
    if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
    // We found an axis, set the range to a max of 10,000
    device.Properties.SetRange(ParameterHow.ById,
    doi.ObjectId, new InputRange(-5000, 5000));
    // Load our feedback file
    EffectList effects = null;
    effects = device.GetEffects(@"C:\MyEffectFile.ffe",
    FileEffectsFlags.ModifyIfNeeded);
    foreach(FileEffect fe in effects)
    EffectObject myEffect = new EffectObject(fe.EffectGuid, fe.EffectStruct,
    device);
    myEffect.Download();
    effectList.Add(myEffect);
    while(running)
    UpdateInputState();
    Application.DoEvents();
    return true;
    public void PlayEffects()
    // See if our effects are playing.
    foreach(EffectObject myEffect in effectList)
    //if (button0pressed == true)
    //MessageBox.Show("Button Pressed.");
    // myEffect.Start(1, EffectStartFlags.NoDownload);
    if (!myEffect.EffectStatus.Playing)
    // If not, play them
    myEffect.Start(1, EffectStartFlags.NoDownload);
    //button0pressed = true;
    protected override void OnClosed(EventArgs e)
    running = false;
    private void UpdateInputState()
    PlayEffects();
    // Check the joystick state
    JoystickState state = device.CurrentJoystickState;
    device.Poll();
    joyState = "Using JoystickState: \r\n";
    joyState += device.Properties.ProductName;
    joyState += "\n";
    joyState += device.ForceFeedbackState;
    joyState += "\n";
    joyState += state.ToString();
    byte[] buttons = state.GetButtons();
    for(int i = 0; i < buttons.Length; i++)
    joyState += string.Format("Button {0} {1}\r\n", i, buttons[i] != 0 ? "Pressed" : "Not Pressed");
    label1.Text = joyState;
    //if(buttons[0] != 0)
    //button0pressed = true;
    public Form1()
    // Required for Windows Form Designer support
    InitializeComponent();
    // TODO: Add any constructor code after InitializeComponent call
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    if( disposing )
    if (components != null)
    components.Dispose();
    base.Dispose( disposing );
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    public void InitializeComponent()
    this.label1 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // label1
    this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.label1.Location = new System.Drawing.Point(8, 8);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(272, 488);
    this.label1.TabIndex = 0;
    // Form1
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.BackColor = System.Drawing.SystemColors.ControlText;
    this.ClientSize = new System.Drawing.Size(288, 502);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
    this.label1});
    this.Name = "Form1";
    this.Text = "Joystick Stuff";
    this.ResumeLayout(false);
    #endregion
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    using (Form1 frm = new Form1())
    frm.Show();
    if (!frm.InitializeInput())
    MessageBox.Show("Couldn't find a joystick.");

    Imho he means the following.
    Your class has performs two tasks:
    Controlling the joystick.
    Managing the joystick with a form.
    So I would recommend, that you separate the WinForm from the joystick code. E.g.
    namespace JoystickCtlLib
    public class JoystickControl
    private Device device = null;
    private bool running = true;
    private ArrayList effectList = new ArrayList();
    private string joyState = "";
    public string State { get { return this.joyState; } }
    public bool InitializeInput() { return true; }
    public void PlayEffects() { }
    private void UpdateInputState() { }
    So that your joystick class does not reference or uses any winform or button.
    btw, there is a thing which is more important than that: Your polling the device in the main thread of your application. This will block your main application. Imho this should be a job for a thread like background worker.

  • Could not find the main class: projectRFID.ProjectGUI. Program will exit.

    Hello,
    I'm quite new in Java. I have an application with GUI. When I'm using Eclipse version 3.4.0 to run the application, all it is working perfect.
    But after I generate the jar from Eclipse, using the manifest file option from there and added the ProjectGUI to it, where is the main class, and try to run from the command line I receive the next error:
    root@slax:~/workspace# java -jar rfid.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: projectRFID/ProjectGUI
    Caused by: java.lang.ClassNotFoundException: projectRFID.ProjectGUI
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: projectRFID.ProjectGUI. Program will exit.
    root@slax:~/workspace#
    I run this application on a SLAX system with jdk6 update 7.
    I tried to generate the jar file even from the command line using the manifest file option but I still receive the same error.
    I hope somebody can help me!
    Thank you!

    cojogrizli wrote:
    The structure of my project in Eclipse is src/project/files.java and in jar file is src/files.java bin/class.java Dati/ and META-INF/.That's wrong. You don't need the .java files in the jar (but you can have them, if you want, they are just not used by Java).
    And each .class file must be in a directory that reflects its package. So in your example ProjectGUI.class must be in the directory projectRFID/ inside the .jar file.

  • Could not find the main class - Problem with Webservice-Access

    Hello Everybody,
    I'm having serious Problems with accessing a WebService (Tomcat-Axis) per executable jar-File.
    I constructed a simple GUI with 3 Textboxes 1 Button and 1 Resultbox.
    I use eclipse so it was no Problem to simple generate the Backgroundclient by Processing the .wsdl-File of the WS.
    Now I do this:
    Head_tServiceLocator serviceLocator = new Head_tServiceLocator();
    Head_t service = serviceLocator.getRPCCall();
    RPCCallSoapBindingStub Head_t = (RPCCallSoapBindingStub) service;and use the Webservice like an Object.
    All this works very well.
    Now the Problem:
    Head_t service = serviceLocator.getRPCCall();this Line has to throw a ServiceException.
    If i add a try-catch Block to Process the Message JAVA tells me after i exported to JAR (with Manifest-stuff and so on) and double Click on the JAR the following :
    Could not find the main Class - Program will exit.
    And if i add a throws Declaration to the Methodheader it tells me:
    Fatal Exception Occured - Program will exit
    But if i Comment out that Line at least the GUI is being displayed (so it DOES find the main-Class). But then of course the Webservice won't be accessed.
    All the JARs needed (axis.jar, commons-discovery.jar and so on) are in the same Directory as the Webservice-Client.jar
    Please Help me.
    Greets,
    Zap

    I am not done any typing mistake while creating the jar file i already followed the suggestion that you have mentioned but still the same error .
    This is my MANIFEST.MF file created under META-INF folder
    Manifest-Version: 1.0
    Class-Path: qtjambi-4.4.3_01.jar qtjambi-win32-msvc2005-4.4.3_01.jar
    Created-By: 1.5.0 (Sun Microsystems Inc.)
    Main-Class: Ui_MainWindow
    When i extracted the app.jar following this i got
    1. META-INF folder inside that MAINFEST.MF file the contents i have already placed above
    2. qtjambi-4.4.3_01.jar
    3. qtjambi-win32-msvc2005-4.4.3_01.jar
    4. Ui_MainWindow.class
    Please tell me whats wrong in that i can also give you the app.jar file please let me know the email id ..

  • "Could ntot find the main class : PdfToImage"

    I am trying to produce a jar that I can execute from the command line. Currently it executes fine if I hit F6 to run the code in the Netbeans IDE.
    I read this article:
         http://java.sun.com/developer/Books/javaprogramming/JAR/basics/run.html
    but still can't get it to run from the command line. The error I get when clicking on the jar file is:
    "Could not find the main class PdfToImage"
    The source code is this:
    package converttoimage2;
    ...import statements here
    public class PdfToImage{
         public static void main(String[] args) {
    To build a jar file I navigated to the NetbeansProjects folder and typed the following (is this wrong?)
         jar cfm PdfToImage.jar ConvertToImage2\manifest.mf ConvertToImage2
    No error messages occured here. The manifest file originally was this (BTW I don't understand what that X-comment is trying to say)
         Manifest-Version: 1.0
         X-COMMENT: Main-Class will be added automatically by build
    so I added this line:
         Main-Class: PdfToImage
    and yes, I pressed Enter at the end of this line. This is the manifest that generates the error. I get the same error this way:
         Main-Class: converttoimage2.PdfToImage
    The code I'm using from the Windows command line to execute the jar (after I copy the jar file to the c-drive) is this:
         java -jar C:\PdfToImage.jar
    This errors out with
         Could not find the main class: PdfToImage
    I've also tried this;
         java C:\PdfToImage.jar
    The next thing i tried was to navigate to the class folder containing the PdfToImage.class. I copied the manifest into this class folder as well.From there I typed:
         jar cfm PdfToImage.jar manifest.mf PdfToImage
    This produced a jar file with no error messages, but I get the original error messsage when I try to execute. Also I doubt this last jar file is complete since it is only 2KB in size (My code references a library called PdfRenderer which is a 2MB jar).
    I'm completely lost here.

    I am trying to produce a jar that I can execute from the command line. Currently it executes fine if I hit F6 to run the code in the Netbeans IDE.You can make a jar from NetBeans, "Build > Build Main Project" (Shortcut - F11). Or right click the project in the project window and select "Build".
    I read this article:
         http://java.sun.com/developer/Books/javaprogramming/JAR/basics/run.html
    OK, if you want to create a jar without Netbeans, then following link would help you a lot:
    [http://java.sun.com/docs/books/tutorial/deployment/jar/index.html]
    Thanks!

  • The manifest file "could not find the main class."

    The main class file is inside a folder in the created Jar file, but is not in a package. But when I double-click the Jar file, it says it could not find the main class. I am using Windows. I have tried each of the following lines in the manifest, but none are working:
    Main-Class: Installer
    Main-Class: setupFiles/programFile/Installer
    Main-Class: setupFiles\programFile\Installer
    Main-Class: setupFiles.programFile.InstallerThe main class is inside the setupFiles/programFile directory. Please Help!
    Thanks in advance,
    ~ Tom

    Hi Tom,
    The main class file is inside a folder in the created
    Jar file, but is not in a package. This is the problem. A JAR file is not an arbitrary ZIP file, where you can arrange directories as you like. The structure of a JAR file always has to follow the package structure. So your Installer class must be on the top level and not in directory setupFiles/programFile.
    You might add non-class files in other directores and can access them as resources, but you have to put the class files into their "natural" directories.

Maybe you are looking for

  • How to set a new email account for iCloud?

    How set a new email account for iCloud?

  • Skype for Business / MS Office

    I have the new Skype for Business client unstalled in my home office PC as part of the MS Office 2013 suite. Can this client be used to log into my personal Skype account? If so, how do you enter the proper credentials?

  • Find manager in workflow...

    Hi, I need to find the manager in the workflow, WHO HAS THE APPROVAL LIMIT. Manager has to have the  approval amount limit. Thanks in advance, Sukumar.

  • Can't add printer connected to other mac on network

    I've got a new Epson Photo Stylus R380 connected via usb to my desktop G4. That G4 is hard wired to my airport express network. I've got the printer drivers, utilities installed on the desktop G4 and the printer works just fine. Now I'd like to print

  • Itunes not appearing on screen after downloading update

    On 10/7/08 I downloaded the itunes update that appeared on the screen. Since then itunes does not load on the screen. Itunes and the toolbar appear at the top but that's all I see. I can click on CONTROLS and then play. the entire music library will