The Artima Developer Community
Sponsored Link

Java Answers Forum
How to convert this application into Applet, Thanks!!

1 reply on 1 page. Most recent reply: Apr 21, 2006 5:19 AM by Kondwani Mkandawire

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 1 reply on 1 page
xu changhui

Posts: 1
Nickname: tianxiao
Registered: Apr, 2006

How to convert this application into Applet, Thanks!! Posted: Apr 17, 2006 6:34 AM
Reply to this message Reply
Advertisement
Application Programme:
import java.io.*;
import javax.swing.*;
public class filepath
{
public static void main(String[] args)
{
String currentFilePath = null;
File file = null;
String currentFileName = null;
JFileChooser jFileChooser = new JFileChooser();
int result = jFileChooser.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION)
{
currentFilePath = jFileChooser.getSelectedFile().getPath();
try
{
file = new File(currentFilePath);
currentFileName = file.getAbsolutePath();
System.out.println(currentFileName);
currentFileName = file.getParent();
System.out.println(currentFileName);
// ...other code
}
catch(NullPointerException npe)
{
String errorMsg = new String("status: Error by opening " );
System.err.println(errorMsg);
}
}

}
}
Applet Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class MainAccess extends JApplet implements ItemListener{

Container container=getContentPane();

JMenuBar menuBar=new JMenuBar();

JMenu menuFile=new JMenu("Îļþ");
JMenuItem inputTerrain=new JMenuItem("ÊäÈëµØÐÎÊý¾Ý");
JPanel panel=new JPanel();
JTextArea text=new JTextArea();
public void init(){
container.setLayout(new FlowLayout());

panel.setLayout(new BorderLayout());
panel.add(text);
container.add(panel);

menuBar.add(menuFile);
inputTerrain.addActionListener(new itemListener());
menuFile.add(inputTerrain);
setJMenuBar(menuBar);
}
public void itemStateChanged(ItemEvent e){

}
class itemListener implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource()==inputTerrain){
//text.append("ok");
String currentFilePath = null;
File file = null;
String currentFileName = null;
JFileChooser jFileChooser = new JFileChooser();
int result = jFileChooser.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION){
currentFilePath = jFileChooser.getSelectedFile().getPath();
try{
file = new File(currentFilePath);
currentFileName = file.getAbsolutePath();
text.append(currentFileName);
//System.out.println(currentFileName);
currentFileName = file.getParent();
text.append(currentFileName);
//System.out.println(currentFileName);
// ...other code
}
catch(NullPointerException npe){
String errorMsg = new String("status: Error by opening " );
System.err.println(errorMsg);
}

}
}
}
}
}
Where is wrong in Applet? Thanks!!!!!!!!


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: How to convert this application into Applet, Thanks!! Posted: Apr 21, 2006 5:19 AM
Reply to this message Reply
Reformat your code and I garauntee you, you'll get some sort
of a response in the right direction.

Flat View: This topic has 1 reply on 1 page
Topic: getting more than 1 row values in a single string Previous Topic   Next Topic Topic: System.currentTimeMillis UTC time problems

Sponsored Links



Google
  Web Artima.com   

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