Basically I have this code and another program that rotates text around the screen and I'm trying to merge them. How do I draw a string to this code without the use of something like
public static void main( String args[] ) //
{ //
(new ViewOfDisplay()).setVisible(true); // Start application
}
I can't change the barebones of the code, just add to
package Clients; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.util.List; import java.util.Map; import java.util.Observer; import java.util.Observable; import Middle.*; class ViewOfDisplay implements Observer { private static final int H = 300; // Height of window pixels private static final int W = 400; // Width of window pixels public ViewOfDisplay( RootPaneContainer rpc ) { // Add code to setup a graphical view of the display } public void update( Observable aModelOfDisplay, Object arg ) { // Code to update the graphical display with the current // state of the system // Orders awaiting processing // Orders being picked in the 'warehouse. // Orders awaitig collection } }
This is the rotating text program
import javax.swing.*; import java.awt.*; import java.awt.geom.*; import java.awt.image.BufferedImage; // Note Menu bar is at the top of the area class Main { public static void main( String args[] ) // { // (new Application()).setVisible(true); // Start application } // } class Application extends JFrame { private static final int H = 300; // Height of window private static final int W = 400; // Width of window private Animate animation; // Active object private String message = "Rotating message "; private Font font = new Font("Monospaced",Font.BOLD,24); public Application() { setSize( W, H ); // Size of drawing area setDefaultCloseOperation(EXIT_ON_CLOSE); animation = new Animate(); // Start chimney smoking animation.start(); } public void update( Graphics g ) // Called by repaint { // drawScreen( (Graphics2D) g ); // Draw Screen } public void paint( Graphics g ) // When 'Window' is first { // shown or damaged drawScreen( (Graphics2D) g ); // Draw Screen } private Dimension theAD; // Alternate Dimension private BufferedImage theAI; // Alternate Image private Graphics2D theAG; // Alternate Graphics public void drawScreen( Graphics2D g ) // Double buffer { // allow resize Dimension d = getSize(); // Size of image if ( ( theAG == null ) || ( d.width != theAD.width ) || ( d.height != theAD.height ) ) { // New size theAD = d; theAI = (BufferedImage) createImage( d.width, d.height ); theAG = theAI.createGraphics(); AffineTransform at = new AffineTransform(); at.setToIdentity(); at.scale( ((double)d.width)/W, ((double)d.height)/H ); theAG.transform(at); } drawActualScreen( theAG ); // Draw actual screen g.drawImage( theAI, 0, 0, this ); } public void drawActualScreen( Graphics2D g )// Actual draw screen { g.setPaint( Color.white ); // Paint Colour g.fill( new Rectangle2D.Double( 0, 0, W, H ) ); g.setPaint( Color.black ); // Paint Colour g.setFont ( font ); FontMetrics fm = getFontMetrics( font ); int width = fm.stringWidth(message); int offset = animation.getPos(); g.drawString( message, offset, 100 ); g.drawString( message, W + offset, 100 ); } class Animate extends Thread { private int pos = 1; // public synchronized int getPos() { return pos; } public synchronized void moveString() // Move string { pos--; // New position if ( pos < -W ) pos = 0; } public void run() // Active part { while ( true ) // Forever { // try // { // moveString(); // Move mess repaint(); // -> update Thread.sleep( 25 ); // Sleep } // loop catch (InterruptedException e) {} // Ignore any error } } } }