//CIS 790 L.A.T.T.C PROF. AUCIELLO // Programmed by Joseph Auciello, CIS Professor, LA Trade Technical College. // a50e /* TOPICS coordinates are col, row = (x,y) = hor, ver */ import corejava.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.awt.Graphics; import java.awt.Font; import java.awt.Color; import java.awt.Image.*; import java.lang.Math; import java.util.Date; import java.util.Random; import java.util.*; public class a50e extends Applet { // all definitions and initializations can go here. TextField textField0, textField1, textField2, textField3, textField4, textField5, textField6; // defines variable textFields // 'awt' (abstract windows toolkit) contains // components, such as: Buttons, Text Fields, etc. Font font2 = new Font("TimesRoman", Font.ITALIC, 20); // Font font3 = new Font("Helvetica", Font.BOLD, 20); Font font5 = new Font("Symbol", Font.BOLD, 20); public void init() { Label namelabel0 = new Label("Font Size:",Label.LEFT); add(namelabel0); textField0 = new TextField(4); add(textField0); textField0.setText("20"); Label namelabel1 = new Label(" Font Height:",Label.RIGHT); add(namelabel1); textField1 = new TextField(4); add(textField1); textField1.setText("15"); Label namelabel2 = new Label(" X (Hor):",Label.RIGHT); add(namelabel2); textField2 = new TextField(4); add(textField2); textField2.setText("70"); Label namelabel3 = new Label(" Y (Ver):",Label.RIGHT); add(namelabel3); textField3 = new TextField(9); add(textField3); textField3.setText("150"); Label namelabel4 = new Label(" Red:",Label.RIGHT); add(namelabel4); textField4 = new TextField(3); add(textField4); textField4.setText("75"); Label namelabel5 = new Label(" Green:"); add(namelabel5); textField5 = new TextField(3); add(textField5); textField5.setText("75"); Label namelabel6 = new Label(" Blue:",Label.RIGHT); add(namelabel6); textField6 = new TextField(3); add(textField6); textField6.setText("250"); } // end init() public void paint(Graphics g) { Font fonts = new Font("Helvetica",Font.BOLD + Font.ITALIC,18); g.setFont(fonts); g.setColor(new Color(22,22,225)); // base color g.drawString("Put line3 on line6 for shadow effect like this!",85,74); String reds = textField4.getText(); String greens = textField5.getText(); String blues = textField6.getText(); int red = Integer.parseInt(reds); int green = Integer.parseInt(greens); int blue = Integer.parseInt(blues); g.setColor(new Color(225,25,25)); // top color g.drawString("Put line3 on line6 for shadow effect like this!",87,74); // 1st line. String s = textField0.getText(); int height0 = Integer.parseInt(s); Font font0 = new Font("TimesRoman", Font.PLAIN, height0); g.setFont(font0); int verx = 100; g.drawString("TimesRoman, font height "+height0+" (1)", 70, verx); verx += 1.25*height0; // 2nd line. FontMetrics fontMetrics = g.getFontMetrics(font0); int height1 = fontMetrics.getHeight(); // get height (attribute) of 'font0'. Font font1= new Font("Helvetica", Font.PLAIN, height1); // Note: Can't define font1 until 'height' is defined. Of Course! g.setFont(font1); g.drawString("font height "+height1+" (based on 1st line) (2)", 70, verx); verx += 1.25*height0; // 3rd line. String hors = textField2.getText(); int hor = Integer.parseInt(hors); String vers = textField3.getText(); int ver = Integer.parseInt(vers); // g.drawString("X @hor "+hor+", ver "+ver+" (3)", 70, verx); // verx += height0; Font font3 = new Font("Symbol",Font.BOLD + Font.ITALIC,height1); g.setFont(font3); g.drawString("Quality in Motion (3)",hor,ver); // 4th, 5th, 6th lines. g.setColor(new Color(red,green,blue)); String height3s = textField1.getText(); int height3 = Integer.parseInt(height3s); Font font4 = new Font("TimesRoman", Font.PLAIN, height3); g.setFont(font4); g.drawString("Font Height=" + height3 + " in " + red+" "+green+" "+blue+" (4)",70,verx+20); g.setFont(font5); g.drawString("Symbol Font in rgb composite color (5).", 70, verx+50); g.setFont(font3); g.drawString("Quality in Motion (6)",70, verx+80); } // end paint() public boolean action(Event event, Object arg) { repaint(); return true; } } // end class // --------------------------------------------------------------- // a50e.java /* QUESTIONS: . IS 'FONT HEIGHT' THE SAME AS 'FONT SIZE'? . NOTE IN THE 2ND LINE, THE FONT HEIGHT IS DERIVED FROM "FONT0". -- EXPLAIN THIS. WHAT COMMANDS ARE USED TO GET THE HEIGHT OF "FONT0"? . WHAT IS A DARKER COLOR 10-10-10 OR 235-235-235? . What happens if Y (ver) is 400? ASSIGNMENT: WRITE THE INSTRUCTIONS TO DISPLAY YOUR NAME IN YELLOW IN THE UPPER LEFT CORNER. ADD ERROR TRAPPING TO PREVENT OUT-OF-BOUNDS NUMBERS. THIS APPLET PROGRAM IS ALL ABOUT INPUTTING VARIABLES, MODIFYING FONTS, COLORS, AND POSITION. THE PRIMARY BENEFIT TO THE PROGRAMMING STUDENT WILL BE THE DRAMATIC VISUAL EFFECTS HIS/HER CHANGES TO THE CODE MAKES. GET INTO IT. MODIFY IT. TEST YOUR CHANGES. MAKE A JOURNAL OF WHAT CODE CHANGES. DO-TEST-REDO-RETEST UNTIL YOU HAVE IT PERFECT! THIS PROGRAM WILL GIVE YOU PRACTICE COMPILING - TESTING - MODIFYING YOUR CODE. SHOW ME WHAT YOU CAN DO. CREATIVE VARIATIONS ARE WORTH EXTRA CREDIT. J.A. 05-24-99. */