//导入包
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import static java.awt.BorderLayout.*;
import javax.swing.JScrollPane;
import java.awt.ScrollPane;
import java.awt.*;
import java.awt.Color.*;
import javax.swing.BorderFactory;
import java.awt.Label.*;
import javax.swing.JSplitPane.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JFileChooser.*;
import javax.swing.JLabel.*;
public class JieMian
{
//定义组件
JFrame jf = new JFrame("FTP文件传输软件");
JPanel jl=new JPanel();
JPanel jl1=new JPanel();
JPanel jl2=new JPanel();
JPanel jl3=new JPanel();
JPanel jl4=new JPanel();
JPanel jl5=new JPanel();
JPanel jl6=new JPanel();
JPanel jl7=new JPanel();
JPanel jl8=new JPanel();
JPanel jl9=new JPanel();
JPanel jl10=new JPanel();
JButton jb=new JButton("连接");
JButton jb1=new JButton("文件");
JButton jb2=new JButton("大小");
JButton jb3=new JButton("类型");
JButton jb4=new JButton("修改日期");
JButton jb5=new JButton("名称");
JButton jb6=new JButton("大小");
JButton jb7=new JButton("类型");
JButton jb8=new JButton("修改日期");
JButton jb9=new JButton("权限");
JButton jb10=new JButton("所属用户/组");
JTextField jtf=new JTextField(20);
JTextField jtf1=new JTextField(10);
JTextField jtf2=new JTextField(10);
JTextField jtf3=new JTextField(5);
JTextField jtf4=new JTextField(31);
JTextField jtf5=new JTextField(31);
JTextArea jta =new JTextArea(20,30);
JScrollPane jsp=new JScrollPane();
public void init()
{
// 为按钮添加背景颜色
jb.setBackground(Color.GRAY);
//设置jl面板的组建排列的方式
jl.setLayout(new BorderLayout(30,5));
//设置边框
jl1.setBorder(BorderFactory.createLoweredBevelBorder());
jl4.setBorder(BorderFactory.createRaisedBevelBorder());
jl3.setBorder(BorderFactory.createEtchedBorder());
jl3.setPreferredSize(new Dimension(400, 500));
jl4.setPreferredSize(new Dimension(400, 500));
jf.add(jl);
jl.add(jl1,NORTH);
jl.add(jl2,SOUTH);
jl2.setLayout(new BorderLayout());
jl2.add(jl3,WEST);
jl2.add(jl4,EAST);
jl3.setLayout(new BorderLayout());
jl3.add(jl5,NORTH);
jl5.setLayout(new FlowLayout());
jl5.add(new Label("本地"));
jl5.add(jtf4);
jl4.setLayout(new BorderLayout());
jl4.add(jl6,NORTH);
jl6.setLayout(new FlowLayout());
jl6.add(new Label("远程"));
jl6.add(jtf5);
jl3.add(jl7,SOUTH);
jl7.setBorder(BorderFactory.createRaisedBevelBorder());
jl7.setPreferredSize(new Dimension(400, 470));
jl7.setLayout(new BorderLayout());
jl7.add(jl8,NORTH);
jl8.setLayout(new FlowLayout());
jl8.add(jb1);
jl8.add(jb2);
jl8.add(jb3);
jl8.add(jb4);
jb1.setBackground(Color.lightGray);
jb2.setBackground(Color.lightGray);
jb3.setBackground(Color.lightGray);
jb4.setBackground(Color.lightGray);
jb5.setBackground(Color.lightGray);
jb6.setBackground(Color.lightGray);
jb7.setBackground(Color.lightGray);
jb8.setBackground(Color.lightGray);
jb9.setBackground(Color.lightGray);
jb10.setBackground(Color.lightGray);
jb1.setPreferredSize(new Dimension(100, 25));
jb2.setPreferredSize(new Dimension(80, 25));
jb3.setPreferredSize(new Dimension(80, 25));
jb4.setPreferredSize(new Dimension(100, 25));
jb5.setPreferredSize(new Dimension(60, 25));
jb6.setPreferredSize(new Dimension(60, 25));
jb7.setPreferredSize(new Dimension(60, 25));
jb8.setPreferredSize(new Dimension(60, 25));
jb9.setPreferredSize(new Dimension(60, 25));
jb10.setPreferredSize(new Dimension(80, 25));
jl4.add(jl9,SOUTH);
jl9.setPreferredSize(new Dimension(400, 470));
jl9.setLayout(new BorderLayout());
jl9.add(jl10,NORTH);
jl9.add(jsp);
jl9.setLayout(new FlowLayout());
jl10.add(jb5);
jl10.add(jb6);
jl10.add(jb7);
jl10.add(jb8);
jl10.add(jb9);
jl10.add(jb10);
jl1.setLayout(new FlowLayout());
//将组件添加到JL1面板上面
jl1.add(new Label("地址栏"));
jl1.add(jtf);
jl1.add(new Label("用户名"));
jl1.add(jtf1);
jl1.add(new Label("密码"));
jl1.add(jtf2);
jl1.add(new Label("端口"));
jl1.add(jtf3);
jl1.add(jb);
jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser jfc=new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );
jfc.showDialog(new JLabel(),"选择");
File file=jfc.getSelectedFile();
if(file.isDirectory()){
System.out.println("文件夹:"+file.getAbsolutePath());
}else if(file.isFile()){
System.out.println("文件:"+file.getAbsolutePath());
}
System.out.println(jfc.getSelectedFile().getName());
}
});
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
}
public static void main(String[] args)
{
new JieMian().init();
}
}
---------- 编译Java程序 ----------
JieMian.java:142: 错误: 找不到符号
JFileChooser jfc=new JFileChooser();
^
符号: 类 JFileChooser
JieMian.java:142: 错误: 找不到符号
JFileChooser jfc=new JFileChooser();
^
符号: 类 JFileChooser
JieMian.java:143: 错误: 找不到符号
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );
^
符号: 变量 JFileChooser
JieMian.java:144: 错误: 找不到符号
jfc.showDialog(new JLabel(),"选择");
^
符号: 类 JLabel
4 个错误
输出完成 (耗时 0 秒) - 正常终止