The Artima Developer Community
Sponsored Link

Java Answers Forum
HI what is wrong with this code???

14 replies on 1 page. Most recent reply: Sep 9, 2003 10:57 PM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 14 replies on 1 page
Ram

Posts: 19
Nickname: srkothuru
Registered: Jul, 2003

HI what is wrong with this code??? Posted: Sep 5, 2003 12:27 PM
Reply to this message Reply
Advertisement
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
 
public class home extends Applet implements ActionListener
{
	private Button offwaltz, nanocad;
	private Panel PagePanel, buttonPanel;
 
	public void loadPanel()
	{
		offwaltz = new Button("OffWaltz");
		offwaltz.addActionListener(this);
		nanocad = new Button("Nanocad");
		nanocad.addActionListener(this);
 
		
		buttonPanel = new Panel(new FlowLayout(FlowLayout.CENTER));
		buttonPanel.add(offwaltz);
		buttonPanel.add(nanocad);
		
		PagePanel = new Panel();
		PagePanel.setLayout(new GridBagLayout());
	
		GridBagConstraints c = new GridBagConstraints();
		c.anchor = GridBagConstraints.NORTH;
		c.gridwidth = 1;
		c.gridx = 0;
		c.gridy = GridBagConstraints.RELATIVE;
		c.weightx = 1;
		c.weighty = 1;
		c.insets = new Insets(10, 0, 10, 0);
		PagePanel.add(buttonPanel, c);
 
		setLayout(new GridBagLayout());
		//PagePanel.setSize(400, 400);
		add(PagePanel, c);
		PagePanel.setLocation(0, 0);
 
		validateTree();
	}
 
	public void actionPerformed(ActionEvent e)
	{
		String s = e.getActionCommand();
		String osCommand = "cmd /q /c start /w";
 
		if (s.equals("OffWaltz"))
	    {
			try
			{
				Runtime.getRuntime().exec(osCommand + "update.bat ");
			}
			catch (IOException ex) 
			{ 
				System.out.println( ex.toString() );    
			}
	    }
	    if (s.equals("Nanocad"))
	    {
		
	    }
		
	}
 
	public static void main(String args[])
	{
		loadPanel page = new loadPanel();
	
	
	}



This is the error i am getting
C:\Test>javac home.java
home.java:75: cannot resolve symbol
symbol  : class loadPanel
location: class home
                loadPanel page = new loadPanel();
                ^
home.java:75: cannot resolve symbol
symbol  : class loadPanel
location: class home
                loadPanel page = new loadPanel();
                                     ^
2 errors


Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: HI what is wrong with this code??? Posted: Sep 5, 2003 2:31 PM
Reply to this message Reply
loadPanel() is not a class. It is a method. You can't declare a variable of this "type", and you can't invoke the new operator with it.

Why are you extending Applet, by the way, if you are going to instantiate the class in a main method? Or is that just for testing?

Ram

Posts: 19
Nickname: srkothuru
Registered: Jul, 2003

Re: HI what is wrong with this code??? Posted: Sep 8, 2003 1:10 PM
Reply to this message Reply
How do i correct that??

David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 2:01 AM
Reply to this message Reply
There's an awful lot of questionable things about this code. Did you write it yourself?

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 3:45 AM
Reply to this message Reply
replace ur main method code by

Frame frame = new Frame();
frame.setSize(800, 600);
home applet = new home();
applet.loadPanel();
frame.add(applet);
frame.addWindowListener(new WindowAdapter()
{
    public void windowClosing(WindowEvent e)
    {
      System.exit(0);
    }
});
frame.setVisible(true);
 

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 3:49 AM
Reply to this message Reply
Same question Ram, why are u extending applet.

And when u are extending applet try to rename the methid loadpanel by init() and call the init.

Putting the ui part in init will help the applet UI to be build automatically when running in an applet viewer.(say internet explorer)


One suggestion :: in future try naming ur class name with a Capital Letter like this class should have been named as Home rather.Will not cause any effect on performence but then java conventions.... :) David any comments :)
cheers

Ram

Posts: 19
Nickname: srkothuru
Registered: Jul, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 8:12 AM
Reply to this message Reply
HI i replaced the code in main by the code that u sent me. The applet is opening but giving the following error


Exception in thread "main" java.lang.IllegalArgumentException: adding a window t
o a container
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at homepage.main(homepage.java:82)


The reason i am writing this is, i have 2 java applications which are to be called from any page or another applet. I have tried with a html page but could not. SO i tried to write another application (i donno if i am right) and had 2 buttons on clicking who starts the other applications.
If u have any other suggestions where i can do easily, please help me.

Also, can anyone suggest a good book or any link that helps me with linked lists and pointers(for C Programming).

Thanks much for ur help mausam and David.

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 8:19 AM
Reply to this message Reply
Could u please paste the code again how u are using the main method like u pasted earlier.

I tried running the code and it ran properly at my side. :)

Ram

Posts: 19
Nickname: srkothuru
Registered: Jul, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 8:30 AM
Reply to this message Reply
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
 
public class homepage extends Frame implements ActionListener
{
	private Button offwaltz, nanocad;
	private Panel PagePanel, buttonPanel;
 
	public void loadPanel()
	{
		offwaltz = new Button("OffWaltz");
		offwaltz.addActionListener(this);
		nanocad = new Button("Nanocad");
		nanocad.addActionListener(this);
 
		
		buttonPanel = new Panel(new FlowLayout(FlowLayout.CENTER));
		buttonPanel.add(offwaltz);
		buttonPanel.add(nanocad);
		
		PagePanel = new Panel();
		PagePanel.setLayout(new GridBagLayout());
	
		GridBagConstraints c = new GridBagConstraints();
		c.anchor = GridBagConstraints.NORTH;
		c.gridwidth = 1;
		c.gridx = 0;
		c.gridy = GridBagConstraints.RELATIVE;
		c.weightx = 1;
		c.weighty = 1;
		c.insets = new Insets(10, 0, 10, 0);
		PagePanel.add(buttonPanel, c);
 
		setLayout(new GridBagLayout());
		//PagePanel.setSize(400, 400);
		add(PagePanel, c);
		PagePanel.setLocation(0, 0);
		
		PagePanel.setSize(300, 300);
		setVisible(true);
 
	}
 
	public void actionPerformed(ActionEvent e)
	{
		String s = e.getActionCommand();
		String osCommand = "cmd /q /c start /w";
 
		if (s.equals("OffWaltz"))
	    {
			try
			{
				Runtime.getRuntime().exec(osCommand + "java -jar offwaltz.jar ");
			}
			catch (IOException ex) 
			{ 
				System.out.println( ex.toString() );    
			}
	    }
	    if (s.equals("Nanocad"))
	    {
		try
			{
				Runtime.getRuntime().exec(osCommand + "java -jar nanocad.jar ");
			}
			catch (IOException ex) 
			{ 
				System.out.println( ex.toString() );    
			}
	    }
		
	}
 
	public static void main(String args[])
	{
		Frame frame = new Frame();
		frame.setSize(800, 600);
		homepage applet = new homepage();
		applet.loadPanel();
		frame.add(applet);
		frame.addWindowListener(new WindowAdapter()
			{    
			public void windowClosing(WindowEvent e) 
				{      System.exit(0);}});
			frame.setVisible(true);
				
			
		
	}
 
}
	

Ram

Posts: 19
Nickname: srkothuru
Registered: Jul, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 8:32 AM
Reply to this message Reply
The error is
C:\ChemvizCD>java homepage
Exception in thread "main" java.lang.IllegalArgumentException: adding a window t
o a container
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at homepage.main(homepage.java:82)

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 8:52 AM
Reply to this message Reply
homepage frame = new homepage();
		
frame.addWindowListener(new WindowAdapter()
{
      	public void windowClosing(WindowEvent e)
       	{
       	   System.exit(0);
        }
});
 
frame.setSize(800, 600);
frame.loadPanel();
frame.setVisible(true);
 


Can u see the difference between the earlier code and this code.

Earlier u were extending Applet so it was to be added to a container.

But now ur homepage extends frame so there is no need to add it to frame.Directly add component to it as u are doing in loadpanel.

When u extend an applet u need to add that to conatiner.

The hierarchy is

java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--java.awt.Panel
|
+--java.applet.Applet

java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--java.awt.Window
|
+--java.awt.Frame





you can not add frame to frame container frnd

Ram

Posts: 19
Nickname: srkothuru
Registered: Jul, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 9:04 AM
Reply to this message Reply
Hi
THanks for your help.This works just perfect except for a small problem.
My buttons"offwaltz" and "nanocad" doesnot work. Any suggestions???
No action is being performed. My idea is to start the other two applications ( offwaltz and nanocad) with these buttons.

I tried a batch file ( "exe.bat") replacing
java -jar offwaltz.jar in the code with
exe.bat


The batch file is given bleow ( nothing in that actually)


java -jar offwaltz.jar

Ram

Posts: 19
Nickname: srkothuru
Registered: Jul, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 9:05 AM
Reply to this message Reply
Hey can i put images in the program that i wrote?? like a logo or something???

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 3:31 PM
Reply to this message Reply
> Also, can anyone suggest a good book or any link that
> helps me with linked lists and pointers(for C
> Programming).

Bruce Eckel's Thinking in C++ covers linked lists; you can find the paper edition pretty easily at a bookstore, library, Amazon.com, etc. and you can get it electronically from his site, http://www.mindview.net. If you really want it in C, not C++, I think there is also a Thinking in C, which probably also covers linked lists (I don't know for sure), but maybe it is only available on the CD that comes with Thinking in C++ and/or Thinking in Java.

Of course, probably most books on C programming cover linked lists. Since linked lists are not exactly bleeding edge technology, you can probably find several C books at your local library that would suffice.

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: HI what is wrong with this code??? Posted: Sep 9, 2003 10:57 PM
Reply to this message Reply
the process is actually taking place in the background.....

check this..
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Flat View: This topic has 14 replies on 1 page
Topic: MouseDrag event Previous Topic   Next Topic Topic: Interview questions

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use