Is there a way to refresh a graphic from the main method? What i have is
public static void main(String ad[]) { // Create the menu bar JMenuBar menuBar = new JMenuBar(); // Create a menu JMenu file = new JMenu("File"); JMenu menu = new JMenu("Theme"); menuBar.add(file); menuBar.add(menu); // Create a menu item JMenuItem exit = new JMenuItem("exit"); JMenuItem def = new JMenuItem ("Updates on next move"); JMenuItem item = new JMenuItem("Xmas"); JMenuItem BB = new JMenuItem("Black and Blue"); JMenuItem RB = new JMenuItem("Black and Red"); JMenuItem WB = new JMenuItem("White and Blue"); file.add(exit); menu.add(def); menu.add(item); menu.add(BB); menu.add(RB); menu.add(WB); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); def.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { r1 = 0; r2 = 255; g1 = 0; g2 = 255; b1 = 0; b2 = 255; ThemeBC = new Color(r1,g1,b1); ThemeF = new Color(r2,g2,b2); } }); WB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { r1 = 255; r2 = 0; g1 = 255; g2 = 0; b1 = 255; b2 = 255; ThemeBC = new Color(r1,g1,b1); ThemeF = new Color(r2,g2,b2); } }); BB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { r1 = 0; r2 = 0; g1 = 0; g2 = 0; b1 = 0; b2 = 255; ThemeBC = new Color(r1,g1,b1); ThemeF = new Color(r2,g2,b2); } }); RB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { r1 = 0; r2 = 255; g1 = 0; g2 = 0; b1 = 0; b2 = 0; ThemeBC = new Color(r1,g1,b1); ThemeF = new Color(r2,g2,b2); } }); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { r1 = 255; r2 = 0; g1 = 0; g2 = 128; b1 = 0; b2 = 0; ThemeBC = new Color(r1,g1,b1); ThemeF = new Color(r2,g2,b2); } }); // Install the menu bar in the frame JFrame jwill = new JFrame(); JDub a=new JDub(); jwill.getContentPane().add(a, BorderLayout.CENTER); jwill.setSize(new Dimension(700,700)); jwill.setResizable(false); jwill.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); jwill.setVisible(true); jwill.setJMenuBar(menuBar); }//end of main class
thats only a snippet of my code (the main class) The variables are all private(global variables)
What i want if for when 1 of the action listeneres are performed it updated my graphic to show the new color layout of the action listener. so how could i force it to update without waiting till the next (action is performed on screen) i have a game that goes with the code and it runs the problem is waiting on the swap method to be called to update the screen with the new themes.