/** * Class P2Info.java -- an information file for assignment 2 * in CS4812. This file is formatted as a .java file, with * extensive comment fields, so that it might be harmlessly * added to a project file in most popular IDEs. This allows * for more convenient consultation of the assignment * specifications during development. * */ class P2Info.java { public static void main(String arg[]) { System.err.println ("This class is not meant to be run"); System.exit(1); } } /** CS 4812: "Stealth" JAVA! Programming Assignment 2 - Fall Quarter, 1998. Program Title: Component Creation Assigned: ---, 1998 Design Doc Due: N/A, though recommended Program Due: before sunrise, ____, 1998 I. FILE PROVIDED =================== You are given two files for this assignment: o P2Info.java - this file. II. DELIVERABLES (what you need to turn in) ============================================== o All files created for your project o Turn materials in using e-mail, or some other means that provides a time-stamp. You can zip them, tar them, uuencode them, or do what you like. If you write a script to install your program in packages, please include a brief "readme" file describing your script. III. LEARNING GOALS ======================= o Component/Container design and manipulation o Lightweight components o Graphics, double buffering o JDK 1.1. Event handling IV. HEADER FILE =================== o Before beginning work, please create a header for your source files. You might find it convenient to use the file provided to CS1502 students. If you don't have a copy of this file, it is reprinted below: */ /** * CS4812: Program #2 * *
* Enter a brief description here * * Revisions: 1.0 DATE, 1998 * Created class XXXXX ** * @author * YOUR NAME GOES HERE * * @version Version 1.0, DATE, 1998 * */ /* V. GENERAL OVERVIEW: CONSTRUCTING A GRAPHICAL TEXT-BEAN ========================================================== Your task is to take portions of the text-based "browser" you created for P1, and create a graphical bean to display the text. Since a number of students were challenged by the parser, I've relaxed the requirements for P2 somewhat. The requirements for P2 will differ from those discussed in class in this respect: You do not have to support HTML tags, though your program should include a basic parser that removes all HTML tags. (Thus, you can use some hacks to strip the HTML, or you can modify the state machine you made for P1.) If you are having difficulty with this part of the program, do not delay; consult with me early. Support for HTML tags (background color, font, etc.) will be considered extra credit. Substantial rewards await for those who support "a fair amount" of HTML. VI. PROGRAM REQUIREMENTS =========================== Create a light-weight component that displays formatted text. The object should allow the user to specify the following parameters: Background/Foreground -- if the user specifies a background color, the foreground color is automatically changed to a contrasting color. Thus, if the background color is black, and the user changes the foreground color to black, the background should adjust to some value that presents a pleasing contrast. The user should also be able to specify both background and foreground colors in a single method. (That way, if the use wants black on black, they can get it.) Width/Height -- the user can specificy the dimensions of the component. Text -- the user can specify the String contents of the container. Alternatively, the user can pass in a URL, and the contents of the URL are retrieved and displayed. (HTML tags are stripped; support for the tags is some easy extra credit.) Margins -- the user can specify top/bottom/left/right margins for the container. Font -- the user can specify the font for all the text. (If you intend to support HTML tags that allow font specifications, then just modify this requirement as needed.) Justification -- the user can right/left and center justification for the text. Give some careful thought on which parameters you will allow in a constructor call, and which parameters are set via modifiers. As with the previous program, you will have to create a text- filling algorithm to format the text. You can use your algorithm from P1, however, you will have to modify the way in which you advanced your column count. You can no longer count on monospaced type! (Hint: have a look at the FontMetrics class.) If you coded things carefully in P1, this single modification should not be too difficult. Finally, the component will allow the user to drag a mouse over the text to raise and lower the text. Alternatively, you can provide some scrollbars (no heavyweights, however). The idea is this: since a limited amount of text will be visible, you should allow the user to use the mouse to adjust the scope of visible text. Your solution should result in fairly smooth scrolling. (Hint: consider drawing the text to an offscreen image, and using a clipping area to quickly blit the visible text to screen; a mouse drag event merely adjusts the blit block size and extent. Reparsing the text with each mouse move will be slow. There are other ways of solving this problem as well.) You may use any ADT you wish for this assignment; gtPage.java is not required, and in fact might not be very useful, since its primary purpose was the creation of a uniform class for serialization. You might find it helpful to display your component in a Frame or applet during development. You could use the following code to get started: import java.awt.*; import java.awt.event.*; public class TestFrame extends Frame { int width, height; int iDefaultWidth = 500; int iDefaultHeight =400; public TestFrame() { super ("CS4812: P2 Test Frame"); this.setLayout(new FlowLayout()); setWidth(iDefaultWidth); setHeight(iDefaultHeight); this.setSize(getWidth(), getHeight()); this.addWindowListener (new WindowAdapter() { public void windowClosing(WindowEvent e) { Window w = (Window) e.getSource(); w.setVisible(false); w.dispose(); System.exit(0); } }); this.setBackground(Color.lightGray); } public int getWidth(){return width;} public int getHeight(){return height;} public void setWidth(int width){this.width=width;} public void setHeight(int height){this.height=height;} public void paint(Graphics g) { super.paint(g); } public void update(Graphics g) { paint(g); } public static void main(String arg[]) { new TestFrame().show(); } } Extra Credit Buffet --------------------- Your primary task is to create a lightweight component. If you finish with this part of the assignment, consider adding other features: * Use reflection to allow support for applet tags. (Hint: this will mean subclassing Container instead of Component; but Containers are Components, afterall.) * As discussed, support a variety of HTML tags. The more the better. * Support a border area that lets the user click and drag to dynamically resize the component. * Add in a border area that gives the component a 3D look. * Support images, or even a background image. * Allow for transparent areas within the lightweight * Make a modest browser to hold the HTML bean. (For this, you can use some heavyweights.) * Do something really, really cool. */