• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display a text file in a new window

 
basa rajesh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//I want to display "file:///c:/1.txt" in a new window when i pressed the button "show window".
//i am running using appletviewer,i am not getting any new window.what is the problem.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.applet.* ;
import java.net.*;
public class app1 extends JApplet implements ActionListener
{
public void init()
{
Container contentpane=getContentPane();
contentpane.setLayout(new FlowLayout());
JButton b1 = new JButton( "show window" );
b1.addActionListener(this);
contentpane.add(b1);
}//init
public void actionPerformed( ActionEvent ae )
{
String str=ae.getActionCommand();
if(str.equals("show window"))
{
AppletContext ac = getAppletContext();
String url ="file:///c:/1.txt";
try
{
URL theurl = new URL(url);
System.out.println("i am showing u the document");
ac.showDocument(theurl,"_blank");
}
catch(MalformedURLException e)
{
System.err.println("Url Not Correct");
}
}//if
}//action performed



} //class

 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Basa,
First of all you need to create a new window in order to show it. You need something like:
JFrame f = new JFrame();
and the f.show() will work.
Regards,
Manfred.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic