2012-02-19 76 views
0

当我尝试使用此代码,我得到以下错误:JFileChooser类

Error: Could not find or load main class jfilechooserexample.JFileChooserExample.

任何帮助,将不胜感激

这是我放在类的代码。

import java.io.*; 
import javax.swing.*; 
import java.awt.event.*; 
import javax.swing.filechooser.FileFilter; 
import javax.swing.filechooser.FileNameExtensionFilter; 

public class JFileChooserExample{ 

public static void getFileName(File f){ 
System.out.println("File is: "+f.getName()); 
} 
public static void main(String[] args) { 
    JPanel panel=new JPanel(); 
    panel.setLayout(null); 
    JButton b=new JButton("Open File"); 
    b.addActionListener(new ActionListener(){ 
     public void actionPerformed(ActionEvent e){ 
     JFileChooser chooser=new JFileChooser(); 
     int ret = chooser.showDialog(null, "Open file"); 
     if (ret == JFileChooser.APPROVE_OPTION) { 
     File file = chooser.getSelectedFile(); 
     getFileName(file); 
     } 
     } 
    }); 
    b.setBounds(10,10,120,20); 
    panel.add(b); 
    JFrame f=new JFrame(); 
    f.add(panel); 
    f.setSize(400,200); 
    f.setVisible(true); 

    } 
} 
+0

不要手动调整大小/定位组件 - 这是LayoutManager的工作 – kleopatra 2012-02-21 09:49:33

回答

1

您的类声明与错误消息不匹配。错误消息列出了包名jfilechooserexample。但是,你的班级不属于你的包裹。

您错过了发布启动参数。我猜他们包含软件包名称。