기본적으로 저는 약간 혼란 스럽습니다. 저는 이클립스 용 WindowsPro Builder 플러그인을 사용하고 있으며, 사용자 정의 initialize() 클래스의 모든 JFrame 구성 요소를 만듭니다. 이것은 저를위한 질문을 창조합니다, 일반적으로 나는 처음에 구성 요소를 정의하므로 공개적으로 저의 프로그램에 액세스 할 수 있습니다. 아니요. 두 번째 수업이 있지만 내 구성 요소에 액세스 할 수 없습니다. 예를 들어 전체 초기화 클래스에 대해 통합 된 ActionListener를 만드는 방법을 이해할 수 없습니다.JFrame을 적절하게 사용하는 방법
또한 입력란을 텍스트 영역에서 가져오고 싶지만 어떻게 할 수 있습니까? 모든 것이 범위를 벗어 났을 때? 당신은 클래스 SaveToFile을 호출 할 수 있습니다, 그 클래스에서 나는 textarea에서 입력을 얻고 싶습니다,하지만 어떻게해야합니까? 일식에 대한
import javax.swing.*;
public class FunctionsGUI {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FunctionsGUI window = new FunctionsGUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public FunctionsGUI() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
System.out.println("Error setting native LAF: " + e);
}
frame = new JFrame();
frame.setBounds(100, 100, 571, 531);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SpringLayout springLayout = new SpringLayout();
frame.getContentPane().setLayout(springLayout);
JTextPane textPane = new JTextPane();
springLayout.putConstraint(SpringLayout.NORTH, textPane, 10, SpringLayout.NORTH, frame.getContentPane());
springLayout.putConstraint(SpringLayout.WEST, textPane, 10, SpringLayout.WEST, frame.getContentPane());
springLayout.putConstraint(SpringLayout.SOUTH, textPane, 462, SpringLayout.NORTH, frame.getContentPane());
springLayout.putConstraint(SpringLayout.EAST, textPane, 545, SpringLayout.WEST, frame.getContentPane());
frame.getContentPane().add(textPane);
frame.setLocationRelativeTo(null);
frame.setTitle("Calcolo");
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu mnFile = new JMenu("File");
menuBar.add(mnFile);
final JMenuItem mntmSave = new JMenuItem("Save");
mntmSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SaveToFile sv = new SaveToFile();
}
});
mnFile.add(mntmSave);
JMenu mnOptions = new JMenu("Options");
menuBar.add(mnOptions);
JMenu mnHelp = new JMenu("Help");
menuBar.add(mnHelp);
final JMenuItem AboutMenu = new JMenuItem("About");
AboutMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(AboutMenu)) {
JDialog dialog = new JDialog();
dialog.setTitle("Search Dialog");
dialog.getContentPane().add(new JLabel("Just a test"));
dialog.setSize(300,300);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setLocationRelativeTo(frame);
dialog.setVisible(true);
if (e.getSource().equals(mntmSave));
SaveToFile sv = new SaveToFile();
}
}
});
mnHelp.add(AboutMenu);
}
}
코드에 감사드립니다. 제 경우에는 완벽합니다. :) – chriskvik
당신을 환영합니다 ... – Vinay