Java:无法将Window的“可见”属性设置为True

时间:2013-09-14 21:07:32

标签: java swing window

这是我第一次得到这个。我已经使用了这两行简单的代码,但出于某种原因,我不能使用第二行;它不会起作用。

Secondary second = new Secondary();
second.setVisible(true);

当我尝试这样做时,它表示meathod“setVisible(boolean)”未定义为秒,当它真的不是时。有什么想法吗?

这是“辅助”课程:

public class Secondary {

private JFrame frmMyGames;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Games window = new Games();
                window.frmMyGames.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public Games() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frmMyGames = new JFrame();
    frmMyGames.setTitle("My Games - Executioner");
    frmMyGames.setBounds(100, 100, 470, 250);
    frmMyGames.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTextArea Games = new JTextArea();
    Games.setEnabled(false);
    Games.setEditable(false);
    Games.setFont(new Font("Calibri", Font.PLAIN, 13));
    Games.setText("Please load a game list.");
    GroupLayout groupLayout = new GroupLayout(frmMyGames.getContentPane());
    groupLayout.setHorizontalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
            .addComponent(Games, GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
    );
    groupLayout.setVerticalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
            .addComponent(Games, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
    );
    frmMyGames.getContentPane().setLayout(groupLayout);

    JMenuBar menuBar = new JMenuBar();
    frmMyGames.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    menuBar.add(mnFile);

    JMenuItem mntmLoad = new JMenuItem("Load List");
    mntmLoad.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Games.setText("");
            Games.setEnabled(true);
            String directory = "C:/Program Files/Executioner/saves/games.ex";

            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new FileReader(directory));
                Games.append(reader.readLine());
                Games.append("\nUsername: " + reader.readLine());
                Games.append("\nPassword: " + reader.readLine());

                Games.append("\n");

                Games.append(reader.readLine());
                Games.append("\nUsername: " + reader.readLine());
                Games.append("\nPassword: " + reader.readLine());

                Games.append("\n");

                Games.append(reader.readLine());
                Games.append("\nUsername: " + reader.readLine());
                Games.append("\nPassword: " + reader.readLine());
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {

                e1.printStackTrace();
            }
            String line = null;
            try {
                while ((line = reader.readLine()) != null) {
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });
    mnFile.add(mntmLoad);

    JMenuItem mntmCloseList = new JMenuItem("Close List");
    mntmCloseList.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Games.setText("Please load a list...");
            Games.setEnabled(false);
        }
    });
    mnFile.add(mntmCloseList);
}

}

0 个答案:

没有答案