Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

connection with java

  Asked By: Thomas    Date: Sep 19    Category: Java    Views: 1108
  

please see the source bellow ,
i want "go button" open a frame and
"DOne button" on the frame open sun
for example.
but this source does not work .


import java.awt.*;
import java.util.*;
import java.applet.*;
import java.io.*;
import java.net.*;
public class one extends java.applet.Applet{
Button b1=new Button("go");
public void init(){
setLayout(null);
setSize(400,200);
add(b1);
b1.setBounds(250,10,100,30);
}
public boolean action(Event e,Object arg){
String s=(String )arg;
Graphics g = getGraphics();
if(e.target instanceof Button){
if(s.equals("go")){
F2 f2=new F2(1);
f2.resize(200,200);
f2.show();
}
}
return true;
}
}
class F2 extends Frame{
Button z=new Button("Done");
public F2(int c){
setBackground(Color.black);
setLayout(null);
z.setBounds(100,60,50,20);
add(z);
}
public boolean handleEvent(Event e){
if(e.id==Event.WINDOW_DESTROY)
dispose();
return super.handleEvent(e);
}
public boolean action(Event e,Object arg){
if(e.target instanceof Button){
GO i=new GO("http://java.sun.com");

}
return true;
}

}
class GO extends java.applet.Applet{
public GO(String str) {
try{
URL url = new URL("http://java.sun.com");
AppletContext context = getAppletContext();
context.showDocument(url);
}catch (MalformedURLException e1){
//System.out.println("h");
}


}
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Jeffrey Washington     Answered On: Sep 19

first apologize for not having enough time to correct
your code,but just telling you some points.

1- you must use "setVisible(true);" in your frame
class to make it visible

2- the way you wrote event handling code is incorrect
for at least the frame  class(I am not sure with the
applet class).you must add ActionListener to your
Button.

3- For showing a html page in your applet  you should
use more complex code this is not the way,but if you
want to just redirect your page you should learn
applet to javascript integration.please consult your
references for this.

 
Didn't find what you were looking for? Find more on connection with java Or get search suggestion and latest updates.




Tagged: