Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run applications??

Status
Not open for further replies.

kosmokramer

Programmer
Sep 8, 2002
73
US
I am pretty new to java, only having worked with simple applets, but now I am trying to create an application since I have to work with file input (I read that that is the easiest way to do it). My question is now that I have compiled the application (I am assuming I still have to use javac.exe), how do I run it? I know that it will not run in a webpage (by the way, is there any way to get around that?), so how does it run? Thanks for any tips!

P.S. if I upload this applet with the file from which it is supposed to read will it be able to work though the web?
 
Hi,
You can run the compiled class files by issuing the command :
java <class name>
By class name I mean you would have saved it as something.java..run it as : java something
By the way I really think you should go through the basics of java by going to some site like Have fun with java!
Cheers
Ravi
 
Hi, thanks for your help. I have already taken a class on Java, so I know the basic stuff, it is just that we never dealt with applications. Anyways, when I compile the program, the compiler does not complain, the only problem is that when I try to run it as you said, the command prompt gives me the following error:
Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: FileDemo2

Here's the code just in case I am missing something stupid.

Code:
import java.io.*;
import java.awt.*;
import java.awt.event.*;

class FileDemo2 extends Frame implements WindowListener, ActionListener
{
	private TextArea inputTextArea;
	private Button loadButton;
	private BufferedReader inFile;
	private TextField nameField;

	public static void main (String [] args)
	{
		FileDemo2 demo = new FileDemo2();
		demo.setSize(300,400);
		demo.makeGui();
		demo.setVisible(true);
	}

	public void makeGui()
	{
		Panel top = new Panel();
		loadButton = new Button(&quot;load&quot;);
		top.add(loadButton);
		loadButton.addActionListener(this);
		nameField = new TextField(20);
		top.add(nameField);
		nameField.addActionListener(this);
		add (&quot;North&quot;, top);
		inputTextArea = new TextArea(&quot; &quot;, 10, 50);
		add (&quot;Center&quot;, inputTextArea);
		addWindowListener(this);
	}

	public void actionPerformed(ActionEvent evt)
	{
		if  (evt.getSource() == loadButton)
		{
			String fileName;
			fileName = nameField.getText();
			try
			{
				inFile = new BufferedReader (new FileReader(fileName));
				inputTextArea.setText( &quot;&quot;);
				String line;
				while( (line = inFile.readLine() ) != null)
				{
					inputTextArea.append(line+&quot;\n&quot;);
				}
			}

			catch (IOException e)
			{
				System.err.println(&quot;Error in file &quot; + fileName + &quot;: &quot; + e.toString() );
				System.exit(1);
			}
		}
	}

	public void windowClosing(WindowEvent e)
	{
		System.exit(0);
	}

	public void windowIconified(WindowEvent e)
	{
	}

	public void windowOpened(WindowEvent e)
	{
	}

	public void windowClosed(WindowEvent e)
	{
	}

	public void windowDeiconified(WindowEvent e)
	{
	}

	public void windowActivated(WindowEvent e)
	{
	}

	public void windowDeactivated(WindowEvent e)
	{
	}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top