Currently I am having a major issue when trying to update my JFrame with new information. I tried the usual invalidate, validate, repaint, ect.
Here is the main code that creates the JFrame:
package Calendar;
import javax.swing.*;
import java.awt.*;
import java.util.GregorianCalendar;
import java.awt.Frame;
public class Main extends JFrame
{
public Main()
{
}
public void makeFrame()
{
JFrame frame = new JFrame("Programming II Project: Calendar");
setLayout(new BorderLayout(0, 5));
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setMinimumSize(new Dimension(640, 384));
}
public void makeCenter(int year, int month)
{
// Add center
//new JFrame();
//this.setVisible(true);
JPanel p = new JPanel(new BorderLayout());
p.add(calendarPanel.makeCalendar(year, month));
add(p, BorderLayout.CENTER);
System.out.println("----- FRAME WINDOWS -----");
Frame[] frames = Frame.getFrames();
for (Frame frame : frames)
System.out.println(frame.getName() + ": " + frame.getClass());
//this.setMinimumSize(new Dimension(512, 384));
}
public void makeEast()
{
JPanel p = new JPanel(new BorderLayout());
Clock myClock = new Clock();
p.add(myClock);
p.setForeground(Color.red);
this.add(p, BorderLayout.EAST);
}
public void makeNorth()
{
// Add north
northPanel np = new northPanel();
this.add(np, BorderLayout.NORTH);
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (ClassNotFoundException e)
{
System.out.println("ClassNotFoundException");
}
catch (InstantiationException e)
{
System.out.println("InstantiationException");
}
catch (IllegalAccessException e)
{
System.out.println("IllegalAccessException");
}
catch (UnsupportedLookAndFeelException e)
{
System.out.println("UnsupportedLookAndFeelException");
}
Main m = new Main();
m.makeFrame();
m.makeCenter(GregorianCalendar.YEAR, GregorianCalendar.MONTH);
m.makeNorth();
m.makeEast();
m.setVisible(true);
}
}
And this is the button code that is suppose to switch the JFrame: This is in a totally differnet class
static class bNextMonth_Method implements ActionListener{
public void actionPerformed (ActionEvent e)
{
if (clickm == 11)
{
clicky = clicky + 1;
clickm = 0;
System.out.println(clickm);
System.out.println(clicky);
Main m = new Main();
m.makeCenter(clicky, clickm);
m.makeNorth();
m.makeEast();
}
else
{
clickm = clickm + 1;
System.out.println(clickm);
System.out.println(clicky);
Main m = new Main();
m.makeCenter(clicky, clickm);
m.makeNorth();
m.makeEast();
}
}
}
Now you'll notice that in the first bit of code in the makeCenter method the commented out stuff. If I un-comment that it the information changes but it creates a new window every time.
Now even though dispose() is not in there currently, I put it in the makeCenter method since that was what was called from the button. I can tell that the button is working properly because
System.out.println("----- FRAME WINDOWS -----");
updates and lists a new frame every time I click.
There has to be something terribly simple.
Also I would like to say that there is another class I left out here called Clock.java.
This does have a timer but I'm not sure if that was interrupting anything.
EDIT: I guess this is what you mean?
public class bNextMonth_Method implements ActionListener{
private Main main;
public bNextMonth_Method(Main main) {
this.main = main;
}
public void actionPerformed (ActionEvent e)
{
if (clickm == 11)
{
clicky = clicky + 1;
clickm = 0;
System.out.println(clickm);
System.out.println(clicky);
main.makeCenter(clicky, clickm);
main.makeNorth();
main.makeEast();
}
else
{
clickm = clickm + 1;
System.out.println(clickm);
System.out.println(clicky);
Main m = new Main();
main.makeCenter(clicky, clickm);
main.makeNorth();
main.makeEast();
}
}
}
That was my best interpretation but that throws
bNextYear_Method(Main) in bNextYear_Method cannot be applied to ()
now i know what that means but how do I go about fixing it?