10 Replies - 2913 Views - Last Post: 01 August 2013 - 09:32 AM Rate Topic: -----

#1 madjass  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 34
  • Joined: 28-September 12

problem: how can i make my code to compile!

Posted 31 July 2013 - 03:52 PM

when im compling this code im getting this error:


C:\java>javac TestBrowser.java
TestBrowser.java:13: error: cannot find symbol
MyWindowAdapter tadapter = MyWindowAdapter(this);
^
symbol: class MyWindowAdapter
location: class TestBrowser
TestBrowser.java:13: error: cannot find symbol
MyWindowAdapter tadapter = MyWindowAdapter(this);
^
symbol: method MyWindowAdapter(TestBrowser)
location: class TestBrowser
2 errors

C:\java>java TestBrowser
Error: Could not find or load main class TestBrowser





 package hello;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

 class MyWindowAdapter extends WindowAdapter {
	TestBrowser testBrowser;
	 public MyWindowAdapter(TestBrowser testBrowser){
	this.testBrowser = testBrowser;
	}
	
	public void windowClosing(WindowEvent we) {
		sampleFrame.setVisible(false);
	}
}


package hello;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class AppletFrame extends Applet{
		Frame f;
	public void init(){
	f = new TestBrowser("A Frame Window ");
	
	f.setSize(250, 250);
	f.setVisibible(true);
	}
	public void start(){
	f.setVisible(true);
	}
	public void stop(){
	f.setVisible(false);
	}
	public void paint(Graphics g){
	g.drawString(" another test", 10,20);
	}
	}


package hello;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;


 class TestBrowser extends Frame {

		TestBrowser (String title){
		super(title);
		// creating a object to handle windows events
		MyWindowAdapter tadapter = MyWindowAdapter(this);
		// register to receive those events
		addWindowListener(tadapter);
		
		}
		
public void paint (Graphics g){
			g.drawString("This is a web browser test", 20, 50);
			}
	}


Is This A Good Question/Topic? 0
  • +

Replies To: problem: how can i make my code to compile!

#2 BenignDesign  Icon User is online

  • holy shitin shishkebobs
  • member icon




Reputation: 5765
  • View blog
  • Posts: 10,082
  • Joined: 28-September 07

Re: problem: how can i make my code to compile!

Posted 31 July 2013 - 03:55 PM

I could be wrong, but this doesn't sound like advanced discussion to me.

Moving to regular Java board.
Was This Post Helpful? 1
  • +
  • -

#3 madjass  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 34
  • Joined: 28-September 12

Re: problem: how can i make my code to compile!

Posted 31 July 2013 - 03:59 PM

well if u were that advance u would've found the solution ;)
Was This Post Helpful? -3
  • +
  • -

#4 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1277
  • View blog
  • Posts: 2,846
  • Joined: 05-April 11

Re: problem: how can i make my code to compile!

Posted 31 July 2013 - 04:17 PM

Basics

Try and declare your MyWindowAdapter public
Was This Post Helpful? 0
  • +
  • -

#5 madjass  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 34
  • Joined: 28-September 12

Re: problem: how can i make my code to compile!

Posted 31 July 2013 - 07:17 PM

i did that but still not working
Was This Post Helpful? -1
  • +
  • -

#6 ConciselyVerbose  Icon User is offline

  • D.I.C Regular

Reputation: 90
  • View blog
  • Posts: 315
  • Joined: 05-July 13

Re: problem: how can i make my code to compile!

Posted 31 July 2013 - 07:21 PM

 MyWindowAdapter tadapter = new MyWindowAdapter(this);


Try fixing line 13 of TestBrowser as well

This post has been edited by ConciselyVerbose: 31 July 2013 - 07:22 PM

Was This Post Helpful? 0
  • +
  • -

#7 madjass  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 34
  • Joined: 28-September 12

Re: problem: how can i make my code to compile!

Posted 31 July 2013 - 07:44 PM

it still the same, but thanks for the heads up on that line.

somehow MyWindowAdapter class is not connecting with the TestBrowser class
Was This Post Helpful? 0
  • +
  • -

#8 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 404
  • View blog
  • Posts: 1,006
  • Joined: 14-November 12

Re: problem: how can i make my code to compile!

Posted 01 August 2013 - 01:24 AM

View Postmadjass, on 01 August 2013 - 07:59 AM, said:

well if u were that advance u would've found the solution ;)


The cheek of some people. 'Cannot find symbol' is the most basic of Java errors. You are also trying to run an applet as an application. Try loading it into your web browser - you know, like JApplets are supposed to be run.
Was This Post Helpful? 0
  • +
  • -

#9 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1910
  • View blog
  • Posts: 3,955
  • Joined: 11-December 07

Re: problem: how can i make my code to compile!

Posted 01 August 2013 - 02:04 AM

Well, most beginners are advanced and regress over time.

Quote

somehow MyWindowAdapter class is not connecting with the TestBrowser class


You're ding things backwards. The applet should not know anything about the frame. Here, I've fixed the applet for you. You can run it in the applet viewer or browser and it will work perfectly.

package hello;

import java.applet.*;
import java.awt.*;

public class AppletFrame extends Applet {
	@Override
	public void paint(Graphics g) {
		g.drawString(" another test", 10, 20);
	}
}



If you want to get it working in a frame then you need a main method to create and set your frame to visible.

In your frame you need to create an instance of the applet, add it to the layout then call init() and start() on the applet object.
Was This Post Helpful? 0
  • +
  • -

#10 madjass  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 34
  • Joined: 28-September 12

Re: problem: how can i make my code to compile!

Posted 01 August 2013 - 09:28 AM

i did not write the code. i copy it from the book " the complete reference - java". im new on applet so im testing the code.
Was This Post Helpful? 0
  • +
  • -

#11 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1910
  • View blog
  • Posts: 3,955
  • Joined: 11-December 07

Re: problem: how can i make my code to compile!

Posted 01 August 2013 - 09:32 AM

Well I am shocked. For the sake of the book, I hope an important part of the lesson has been lost in translation.

Did you try any of my suggestions? I tried them out before I posted and know they work.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1