?? filepanel.java
字號(hào):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class FilePanel extends JPanel
{
FilePanel(String str)
{
JLabel label = new JLabel(str);
JTextField fileText = new JTextField(34);
JButton browse = new JButton(" 瀏覽... ");
this.add(label);
this.add(fileText);
this.add(browse);
clickAction ca = new clickAction(this);
browse.addActionListener(ca);
}
public String getFileName()
{
JTextField jtf = (JTextField)this.getComponent(1);
return jtf.getText();
}
private class clickAction implements ActionListener
{
private Component cmpt;
clickAction(Component c)
{
cmpt = c;
}
public void actionPerformed(ActionEvent event)
{
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File(""));
int ret = chooser.showOpenDialog(cmpt);
if(ret==JFileChooser.APPROVE_OPTION)
{
JPanel jp = (JPanel)cmpt;
JTextField jtf = (JTextField)jp.getComponent(1);
jtf.setText(chooser.getSelectedFile().getPath());
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -