Home > Archive > Java Help > May 2004 > problem getting the window to repaint()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problem getting the window to repaint()
|
|
| Joe Vasher 2004-05-16, 5:31 pm |
|
below is the JFrame class that I'm experimenting with. While doing so, I
discovered, I don't have a clue how the overridden paint() method works.
I tried several experiments to get the window to resize correctly.
the DayPlanner class is basically a fillRect(); which I included the
source at very bottom.
I have tried two listeners and addNotify to get the rectangle to refill
the window. But it never gets repainted during resize. I did have
repaint() in the listeners. But took them out.
If you could link me an example of what I'm trying to do or explain what
I'm missing I would surely appreciate it.
I plan on adding a scroll bar to the CalendarView, that is why I'm using
JFrame. DayPlanner is going to be a self contained component (eventually.)
/*
* CalendarView.java
*
* Created on May 12, 2004, 1:16 AM
*/
package jnj_development.com.view;
import jnj_development.com.util.PDataStorage;
import javax.swing.*;
import java.awt.*;
/**
*
* @author jvasher
*/
public class CalendarView extends javax.swing.JFrame
{
DayPlanner dayPlanner;
Graphics graphics;
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
PDataStorage prgData;
Rectangle viewLocation = new Rectangle(); // main frame location.
private int x, y, width, height;
/** Creates new form CalendarView */
public CalendarView()
{
prgData = new PDataStorage( "CalendarView" );
initComponents();
dayPlanner = new DayPlanner( graphics = this.getGraphics() );
setTitle( "Schedule Assistant");
viewLocation.width = prgData.intValue( "width", 500 );
viewLocation.height = prgData.intValue( "height", 380 );
viewLocation.x = prgData.intValue( "startX", (screenDim.width
- viewLocation.width) / 2 );
viewLocation.y = prgData.intValue( "startY", (screenDim.height
- viewLocation.height) / 2 );
setBounds( viewLocation );
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent
evt) {
CalenderViewResized(evt);
}
});
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
addWindowStateListener(new java.awt.event.WindowStateListener() {
public void windowStateChanged(java.awt.event.WindowEvent
evt) {
CalendarViewStateChanged(evt);
}
});
pack();
}
private void CalenderViewResized(java.awt.event.ComponentEvent evt) {
// TODO add your handling code here:
}
private void CalendarViewStateChanged(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
// sets screen start location and size then stores.
prgData.setIntValue( "height", this.getHeight() );
prgData.setIntValue( "width", this.getWidth() );
prgData.setIntValue( "startX", this.getLocation().x );
prgData.setIntValue( "startY", this.getLocation().y );
prgData.store();
System.exit(0);
}
public void addNotify()
{
super.addNotify();
repaint();
}
public void paint( Graphics graphics )
{
Rectangle dayPlannerDim = new Rectangle();
dayPlannerDim.width = this.getWidth();
dayPlannerDim.height = this.getHeight();
dayPlannerDim.x = 0;
dayPlannerDim.y = 28;
dayPlanner.setBounds( dayPlannerDim );
dayPlanner.drawDayPlanner();
}
/**
* @param args the command line arguments
*/
public static void main( String args[] )
{
new CalendarView().show();
}
// Variables declaration - do not modify
// End of variables declaration
}
DAYPLANNER CLASS
/*
* DayView.java
*
* Created on May 16, 2004, 3:39 PM
*/
package jnj_development.com.view;
import java.awt.*;
/**
*
* @author jvasher
*/
public class DayPlanner
{
Graphics2D g2D;
Rectangle dayPlannerDim;
/** Creates a new instance of DayView */
public DayPlanner( Graphics g )
{
g2D = (Graphics2D)g;
}
public void setBounds( Rectangle dim )
{
dayPlannerDim = dim;
}
public void drawDayPlanner()
{
g2D.setColor( Color.YELLOW );
g2D.fillRect( dayPlannerDim.x, dayPlannerDim.y,
dayPlannerDim.width, dayPlannerDim.height );
}
}
| |
|
|
|
|
|
|
|