2014-04-17 3 views
0

방금 ​​자바 GUI 기술을 공부하기 시작했고 그 메뉴 안에 메뉴와 메뉴가있는 작은 프로그램을 만들었습니다. 이제는 파일 선택기를 구현하여 메뉴 항목을 선택하면 파일 선택기가 실행됩니다. 문제는 내가 만든 파일 선택기가 다른 클래스에 있다는 것입니다. 메뉴에있는 항목을 클릭 할 때 파일 선택기의 클래스를 시작할 수 있습니까? 당신이 JFileChooser를 사용하려는 경우 여기 내 코드자바 스윙 메뉴 초보자 어드바이스

public class menu { 


    public static void main(String[] args){ 


//to menu 
JFrame frame = new JFrame("Menu"); 
frame.setVisible(true); 
frame.setSize(600,400); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 


JMenuBar bar = new JMenuBar(); 
frame.setJMenuBar(bar); 
JMenu search = new JMenu("Browse"); 
bar.add(search); 
final JMenuItem songstoplay = new JMenuItem("Browse Songs To Play"); 
search.add(songstoplay); 



//to outline 
    final Container content = frame.getContentPane(); 
    content.setLayout(new GridLayout(3, 1)); 
    JLabel text = new JLabel("My first iteration", JLabel.CENTER); 
    text.setVerticalAlignment(JLabel.TOP); 
    text.setFont(new Font("Serif", Font.PLAIN, 30)); 
    content.add(text); 


JLabel text2 = new JLabel(); 


text2.setText("List of drives connected: C:/"); 
text2.setFont(new Font("Serif", Font.PLAIN, 20)); 
    text2.setVerticalAlignment(JLabel.TOP); 
content.add(text2); 


} 
} 
+0

당신이 파일을 호출 시도 유무 : http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html

또는 위의 예에서 코드에 직접 링크 : 더 나은 당신은 이것 좀보세요? – Ziker

+1

['JFileChooser'] (http://docs.oracle.com/javase/7/docs/api/javax/swing/JFileChooser.html)를 사용해 보시지 않으시겠습니까? – maxx777

+0

답장을 보내 주셔서 감사합니다. 그러나 이것은 메뉴 선택 항목이 선택된 파일 선택기를 사용하는 방법을 묻는 것입니다. – user3449550

답변