자바 파일 다이얼로그
public class Test extends JFrame implements ActionListener{
private JPanel contentPane;
public static void main(String[] args) {
Test frame = new Test();
frame.setVisible(true);
}
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("버튼");
btnNewButton.setFont(new Font("굴림", Font.PLAIN, 30));
btnNewButton.setBounds(76, 72, 240, 102);
contentPane.add(btnNewButton);
btnNewButton.addActionListener(this);
btnNewButton.setActionCommand("event");
}
@Override
public void actionPerformed(ActionEvent e) {
switch(e.getActionCommand())
{
case "event":
//this는 프레임을 가르킴
FileDialog fileDialog = new FileDialog(this,"파일 열기");
//생성자 호출시 다이얼로그가 만들어진다.
JOptionPane.showMessageDialog(null,fileDialog.getDirectory() + fileDialog.getFile());
//getFile() 함수를 통해 파일 이름을 알 수 있다.
break;
}
}
}