Calling one JFrame from another using Timer without any buttons

Your question is very unclear, but the use of multiple frames is not recommended. As an alternative, consider a modeless dialog, shown below. The dialog’s enclosed JOptionPane listens for a PropertyChangeEvent, while counting down from TIME_OUT using javax.swing.Timer. The JOptionPane button is convenient but not required. import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import … Read more

How do I Switch JPanels inside a JFrame

Instead of trying to add an remove components, use a CardLayout CardLayout cardLayout = new CardLayout(); JPanel mainPanel = new JPanel(cardLayout); MenuPanel menu = new MenuPanel(); GamePanel game = new GamePanel(); mainPanel.add(menu, “menu”); mainPanel.add(game, “game”); … public void gameOn() { cardLayout.show(mainPanel, “game”); } When gameOn() is called, the menu will get pushed to the back, … Read more

Java Bouncing Ball

With your current approach… The main problem I can see is that you are placing two opaque components on top of each other…actually you may find you’re circumventing one of them for the other… You should be using a null layout manager, otherwise it will take over and layout your balls as it sees fit. … Read more

Only one component shows up in JFrame

The content pane of a JFrame has a BorderLayout. If you place a component in a BL with no constraints it ends up in the CENTER. The center can only display one component. For an immediate effect, I suggest: f.add(top, BorderLayout.PAGE_START); f.add(mid); f.add(bot, BorderLayout.PAGE_END); Other points. Take out f.setSize(500, 500); and call pack() immediately before … Read more

Unresponsive KeyListener for JFrame

If you don’t want to register a listener on every component, you could add your own KeyEventDispatcher to the KeyboardFocusManager: public class MyFrame extends JFrame { private class MyDispatcher implements KeyEventDispatcher { @Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { System.out.println(“tester”); } else if (e.getID() == KeyEvent.KEY_RELEASED) { System.out.println(“2test2”); } else if … Read more