Note that there are some explanatory texts on larger screens.

plurals
  1. POCompiles and runs but it's not there
    primarykey
    data
    text
    <p>I am trying to run my JFrames from a package folder (which works and has been set up correctly). The problem is that it compiles and runs but I can't see anything and I do not know what to fix since there are no errors. I am probably overlooking something very small, but I just can't pinpoint it. This code is my Main class and the first JFrame class I will be using. Any ideas on how to most efficiently implement a JFrame from a package would be much appreciated.</p> <pre><code>import GroupProject.GUI.Package.*; import javax.swing.*; import java.awt.*; import java.io.*; public class TestGuiApp1 { public static void main(String[] Args) { // Gets screen dimensions to be used to center JFrame Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getScreenSize(); //creates new Main Menu Frame from GUI packages new MainMenuFrame(); //constraints and unlocking/locking features //setLocation((d.width/2)-350, (d.height/2)-350); //setResizable(false); } } </code></pre> <p>//<strong>Start of JFrame class from package</strong></p> <pre><code> package GroupProject.GUI.Package; import javax.swing.*; import java.awt.*; import java.awt.event.*; import com.sun.java.swing.plaf.nimbus.*; public class MainMenuFrame extends JFrame { private JButton guess_word, guess_number, player_stats; private JLabel pic_label = new JLabel(new ImageIcon("Question-Mark-Man.jpg")); public MainMenuFrame() { try { UIManager.setLookAndFeel(new NimbusLookAndFeel() { public UIDefaults getDefaults() { UIDefaults ret = super.getDefaults(); ret.put("defaultFont", new Font(Font.MONOSPACED, Font.BOLD, 16)); return ret; } }); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); ButtonListener listener = new ButtonListener(); // Panel Size setPreferredSize(new Dimension(550, 300)); // Background Color setBackground(new Color(127, 157, 217)); p1.setBackground(new Color(127, 157, 217)); // -------------------- Buttons ------------------- // Guess a word Button guess_word = new JButton("Guess a word", new ImageIcon("word game.png")); guess_word.setFont(new Font("ariel narrow",Font.BOLD,24)); guess_word.addActionListener(listener); p1.add(guess_word); // Guess a number Button guess_number = new JButton("Guess a number", new ImageIcon("number game.png")); guess_number.setFont(new Font("ariel narrow",Font.BOLD,24)); guess_number.addActionListener(listener); p1.add(guess_number); // View player stats button player_stats = new JButton("Player Stats", new ImageIcon("stats2.png")); player_stats.setFont(new Font("ariel narrow",Font.BOLD,24)); player_stats.addActionListener(listener); p1.add(player_stats); // --------------------------------------------------- // ============ Layouts using group layout ============ GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false) .addComponent(guess_word, GroupLayout.PREFERRED_SIZE, 280, GroupLayout.PREFERRED_SIZE) .addComponent(guess_number, GroupLayout.PREFERRED_SIZE, 280, GroupLayout.PREFERRED_SIZE) .addComponent(player_stats, GroupLayout.PREFERRED_SIZE, 280, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(p2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false) .addComponent(p2, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(guess_word, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(guess_number, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(player_stats, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE))) .addContainerGap(239, Short.MAX_VALUE))); // =================================================== p2.add(pic_label); } catch (Exception ex) { throw new Error(ex); } } private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { //need to set values to remember what game the user wants to play // before it goes to the SelectPlayerTypeFrame if (e.getSource() == guess_word) ;//new MainMenu(); if (e.getSource() == guess_number) ; // new MainMenu(); if (e.getSource() == player_stats) ;//new MainMenu(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload