It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Trying to run class in JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Trying to run class in JFrame" Watch "Trying to run class in JFrame" New topic
Author

Trying to run class in JFrame

Anthony Schmitt
Ranch Hand

Joined: Nov 17, 2009
Posts: 37
I've been trying for the last several days to get either an instance of a class (or an applet which does the same thing) to run in an application I have written. It's a pretty robust piece of software, which may be why I'm not able to implement it successfully. I posted about this yesterday but sadly didn't end up with a working solution.

My IDEAL would be to run this plugin in a frame, I assume. The applet was, I had hoped, the easier of the two solutions but after spending about 20 hours trying to get this to work I may have been mistaken. I'm very new to Java, sort of learning by trial-by-fire, and up until now, it was going OK. I'm probably missing something very simple. I'll try to explain it as best I can:

The plugin is called JTA. It's an SSH terminal that can run as an applet or independantly.

From the website, http://javassh.org/space/Installing+as+a+local+Telnet/SSH+Application:
There are two ways to operate the program. One is to simply start it and to configure everything within the application or to give arguments, like host and port, on the command line. The first way may be the least complicated as the menu entries are self descriptive. End users may find the application mode interesting as it provides a fast and reliable telnet implementation to login to other workstations or text-based online games, such as MUDs.


Regarding MAIN, the class I am attempting to run in my frame:

The Application (Main)
There are two ways to operate the program. One is to simply start it and to configure everything within the application or to give arguments, like host and port, on the command line. The first way may be the least complicated as the menu entries are self descriptive. You need to have installed a java runtime environment or java development kit to run the application. On Microsoft Windows systems an installed Internet Explorer with Java support should suffice though.
Quickstart
Make sure either the program java (JRE, JDK) or jview (Windows IE) is in your path. Optionally you may set the environment variable CLASSPATH to point to the file jta20.jar (see the box to the right for more information). Then try the following command:

JRE or JDK on UNIX or Windows (for Windows and IE installed, use jview instead)
java de.mud.jta.Main
alternative:
java -jar jta20.jar
Now you should see the following output:
** JTA - Telnet/SSH for the JAVA(tm) platformn
** Version 2.0 for Java 1.1.x and Java 2
** Copyright (c) 1996-2000 Matthias L. Jugel, Marcus Meissner
** Build: 20000627-1208
jta: loading plugin 'Status' ...
jta: loading plugin 'Socket' ...
jta: loading plugin 'Telnet' ...
jta: loading plugin 'Terminal' ...

Some other messages might appear, but unless you see an Exception a window should appear on your screen and prompt you for login into your local host. If you are running on windows you will probably see an error message and should append the target host you want to connect to to the command line above.
Command Line Options
The application understand several command line arguments to configure the way it looks and where to initially connect to. The following command line arguments are possible:
de.mud.jta.Main [-plugins pluginlist]
[-addplugin plugin]
[-config file]
[host [port]]
(Options enclosed in brackets are optional and may be left out.)





I have attempted to use this is a JInternalFrame and also in a new test application. For the sake of simplicity I'll post my test application:



and Main:




It seems I can't figure out how to run it correctly. The error I'm getting is NO SUITABLE METHOD FOUND FOR ADD.



Full disclosure, I posted about this in applets yesterday when I was trying the applet approach!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Is this a compiler error or a runtime error? If it's a compiler error, which line is causing it? If it's a runtime error, what's the exception stack trace?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anthony Schmitt
Ranch Hand

Joined: Nov 17, 2009
Posts: 37
It's a compile error:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.awt.Panel.add
at applettester.TestFrame.<init>(AppletTester.java:28)
at applettester.TestFrame.main(AppletTester.java:38)


So,

topPanel.add(amain);

and

TestFrame mainFrame = new TestFrame();
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Anthony Schmitt wrote:

You're trying to add a Main object to topPanel. However, you can only add things that are components to containers like topPanel. Since class Main does not extend java.awt.Component or any of its (direct or indirect) sub classes, you can't add it to a container.
Anthony Schmitt
Ranch Hand

Joined: Nov 17, 2009
Posts: 37
Rob Spoor wrote:
Anthony Schmitt wrote:

You're trying to add a Main object to topPanel. However, you can only add things that are components to containers like topPanel. Since class Main does not extend java.awt.Component or any of its (direct or indirect) sub classes, you can't add it to a container.



Gotcha. Main extends object according to the documentation, so how DO I add it if not through frame.add?
Anthony Schmitt
Ranch Hand

Joined: Nov 17, 2009
Posts: 37
I managed to run it by pasting the code from main.java (from the source code) into my tester application, so I KNOW I can get this thing to run in my frame! I just don't know HOW...

I noticed main.java creates a JFrame of it's own...maybe I could change that to my frame?

Anthony Schmitt
Ranch Hand

Joined: Nov 17, 2009
Posts: 37
Main.class creates a frame...



Is there some way to simply tell Main.class to use the JInternalFrame I made in my application instead of making the new Frame?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to run class in JFrame
 
Similar Threads
Enabling a disabled Menu Item
JTableHeader column selection
Trying to run applet in JEditor
JDesktopPane creates inner frame menuItem actionPerformed does not.
Using JMenuItem/Exit not working, about is