public void run() { while (true) { myFrame.renderScreen(); try { Thread.sleep(20L); } catch (InterruptedException ex) { } ; } }
/** * Sets the ui enable. * * @param isEnable should the UI enable? * @param isShutdown should the UI shutdown? */ private void setUIEnable(boolean isEnable, boolean isShutdown) { String msg = ""; Color screenColor = Color.RED; if (!isEnable) { // disable the UI if (isShutdown) { msg = "Shutdown"; screenColor = Color.GRAY; } else { msg = "Fatal halt"; } myFrame.getContentPane().removeAll(); // remove existing content // add new panel JPanel panel = new JPanel(new GridBagLayout()); JLabel label = new JLabel(msg); label.setForeground(Color.WHITE); panel.setBackground(screenColor); panel.add(label, new GridBagConstraints()); myFrame.getContentPane().add(panel); myFrame.getContentPane().revalidate(); myFrame.getContentPane().repaint(); } else { System.out.println("Enabling frame"); myFrame.getContentPane().removeAll(); // remove existing content myFrame.getContentPane().add(myPanel); myFrame.getContentPane().revalidate(); myFrame.getContentPane().repaint(); } }
/** @param args the command line arguments */ public static void main1(String[] args) { MyFrame myframe = new MyFrame(); P1 p1 = new P1(); P2 p2 = new P2(); JButton firstBtn = new JButton("First Button"); JButton secondBtn = new JButton("Second Button"); JButton thirdBtn = new JButton("Third Button"); JButton fourthBtn = new JButton("Fourth Button"); // p1.add(firstBtn); // p1.add(secondBtn); // p2.add(thirdBtn); // p2.add(fourthBtn); myframe.add(p1); myframe.add(p2); // myframe.add(firstBtn); // myframe.add(secondBtn); myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myframe.setVisible(true); }
public static void main(String[] args) { lm = InitialisationAppli.initialisationEntree(); MyFrame frame = new MyFrame(); frame.setBackground(Color.BLUE); frame.setVisible(true); }