PlotterAWTpublic class PlotterAWT extends Plotter A Plotter subclass for drawing into an AWT Window. Reflecting back
to AWT gives us a "known working" plotter to test on.
You can also steal this as a basis for your own plotter driver! |
Fields Summary |
---|
Frame | f | PCanvas | p | Graphics | g | Font | font | FontMetrics | fontMetrics |
Constructors Summary |
---|
PlotterAWT()
super();
f = new Frame("Plotter");
p = new PCanvas(MAXX, MAXY);
f.add(p);
f.pack();
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// If we do setVisible and dispose, then the Close completes
PlotterAWT.this.f.setVisible(false);
PlotterAWT.this.f.dispose();
System.exit(0);
}
});
g = p.getOsGraphics();
|
Methods Summary |
---|
public void | drawBox(int w, int h)
g.drawRect(curx, cury, w, h);
p.repaint();
| void | drawString(java.lang.String s)
g.drawString(s, curx, cury);
curx += fontMetrics.stringWidth(s);
| public void | moveTo(int absx, int absy)
if (!penIsUp)
g.drawLine(curx, cury, absx, absy);
curx = absx;
cury = absy;
| void | penColor(int c)
switch(c) {
case 0: g.setColor(Color.white); break;
case 1: g.setColor(Color.black); break;
case 2: g.setColor(Color.red); break;
case 3: g.setColor(Color.green); break;
case 4: g.setColor(Color.blue); break;
default: g.setColor(new Color(c)); break;
}
| void | penDown() penIsUp = false;
| void | penUp() penIsUp = true;
| public void | rmoveTo(int incrx, int incry)
moveTo(curx += incrx, cury += incry);
| void | setFont(java.lang.String fName, int fSize)
font = new Font(fName, Font.BOLD, fSize);
fontMetrics = p.getFontMetrics(font);
| public void | setdir(float deg)
|
|