Right now I am doing a project in my Computer science IB (International baccalaureate) Higher level program, and I am having trouble with a repaint method within my code.
The current issue is that, I have a base frame that needs to be repainted when a button is pressed from another frame in another class.
The base is that the actionPerformed method in class Months needs to call the paintComponent method in class Calander1. Both classes are different and have seperate frames
Code is shown below, I need the monthListener to basically call the paintComponent method in the other class
class monthListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("jan")){
month = "jan";
Calander1 calander = new Calander1();
calander.repaints();
}
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Months month = new Months();
System.out.println(month.getMonth());
System.out.println("Called the paintComponent outside");
if (month.getMonth().equals("jan")){
System.out.println("Called the paintComponent inside");
}
// Setting the variables in the frame to the correct amount
friends = friends();
school = school();
activities = activities();
startTime1 = start();
endTime1 = end();
amount = amount();
if (friends==0 && activities == 0){
school = 0;
}
else{
school = school - friends - activities;
}
// The next section includes drawing the rectangle and the strings
// inside the rectangle
for (int count = 0; count < 7; count++) {
for (int count2 = 0; count2 < 5; count2++) {
g.drawRect(x, y, 100, 100);
if (count2 == 0 && count == 1) {
g.drawString("Total events " + amount, x + 5, y + 11);
g.drawString("School Events: " + school, x + 5, y + 30);
g.drawString("Friend Events: " + friends, x + 5, y + 49);
g.drawString("Activity Events: " + activities, x + 5,
y + 65);
g.drawString("Start of Events: " + startTime1, x + 5,
y + 80);
g.drawString("End of Events: " + endTime1, x + 5, y + 99);
}
y += 100;
}
y = 100;
x += 100;
}
// This section includes drawing the days of the week
for (int count = 0; count < 7; count++) {
g.setFont(daysFont);
g.setColor(Color.BLUE);
g.drawString(days[count], daysX, daysY);
daysX += 100;
}
}

New Topic/Question
Reply



MultiQuote








|