Refreshing from teh main class
Is there a way to refresh a graphic from the main method? What i have is
Code java:
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.
Re: Refreshing from teh main class
I might be the only one, but I have no clue what you are asking. Do you want to just repaint a component? Call repaint() from the appropriate location, or perform the appropriate method calls to update the user interface.
Re: Refreshing from teh main class
I want the entire scren to refresh when 1 of the actionlisteners are activated.
Re: Refreshing from teh main class
Quote:
Originally Posted by
J-Will
I want the entire scren to refresh when 1 of the actionlisteners are activated.
Did you call repaint on the parent container? If yes, and it didn't work, I recommend trimming your code down to an SSCCE to illustrate your issue more clearly
Re: Refreshing from teh main class
basically is there a way to run a non static method in a static location? I.E. the nonstatic method of repaint(); in the static method of the main class?
Re: Refreshing from teh main class
Quote:
Originally Posted by
J-Will
basically is there a way to run a non static method in a static location? I.E. the nonstatic method of repaint(); in the static method of the main class?
There shouldn't be a need to call these methods from the main method, which actually exists as soon as your code creates the GUI. Call it from the EDT, for instance within the actionPerformed method, or use a SwingTimer if you wish to do this at a later time and/or periodically. Again, I recommend posting an SSCCE and more clearly define your requirements to better illustrate the problem.
Re: Refreshing from teh main class
I would but im on a computer without a jdk so I can not get to the data right this second to see if it is compilable. It will be roughly 2 hours before i can create a SSCCE