I could use some java help working with Applets and the Graphics class. Assignment is due by Midnight.
If you can help, send me an IM... Tasselfoot.
Thanks.
-Tass
PS... the code:
code updated...
If you can help, send me an IM... Tasselfoot.
Thanks.
-Tass
PS... the code:
Code:
import javax.swing.JOptionPane; import java.applet.*; import java.awt.*; public class BarNumber extends Applet /*{ public static void main(String[] boob) //this won't run in JCreator w/o the main, but regardless I can't get the { //program to call the paint() method. :( BarNum fifteen = new BarNum(); fifteen.init(); } } class BarNum extends Applet */ { String num;//instance variable int sum = 0; Graphics g; public void init() { num = JOptionPane.showInputDialog("Type a 15-digit number"); checkLength(num); } public void checkLength(String s)//added this extra, to verify the length of the inputted number { int len = s.length(); if(len != 15) { System.out.println("This number is not 15 digits"); } } public void paint(Graphics g)//no idea what to write here { processAllLines(g); line(g); processSum(g, sum); //System.out.println("I got to paint"); } public void drawBars(Graphics g, int xStart, int yStart, boolean upperLeft, boolean top, boolean upperRight, boolean lowerRight, boolean bottom, boolean lowerLeft, boolean middle) { g.drawLine(xStart, yStart, 25, 0);//upperLeft g.drawLine(xStart + 25, yStart, 0, 25);//top g.drawLine(xStart + 25, yStart + 25, -25, 0);//upperRight g.drawLine(xStart, yStart + 25, -25, 0);//lowerRight g.drawLine(xStart - 25, yStart + 25, 0, -25);//bottom g.drawLine(xStart - 25, yStart, 25, 0);//lowerLeft g.drawLine(xStart, yStart, 0, 25);//middle //System.out.println("I got to drawBars"); } public void processDigit(Graphics g, int xStart, int yStart, int digit) { switch(digit)//am I missing more to this method? { case 0: drawBars(g, xStart, yStart, true, true, true, true, true, true, false); break; case 1: drawBars(g, xStart, yStart, false, false, true, true, false, false, false); break; case 2: drawBars(g, xStart, yStart, false, true, true, false, true, true, true); break; case 3: drawBars(g, xStart, yStart, false, true, true, true, true, false, true); break; case 4: drawBars(g, xStart, yStart, true, false, true, true, false, false, true); break; case 5: drawBars(g, xStart, yStart, true, true, false, true, true, false, true); break; case 6: drawBars(g, xStart, yStart, true, false, false, true, true, true, true); break; case 7: drawBars(g, xStart, yStart, false, true, true, true, false, false, false); break; case 8: drawBars(g, xStart, yStart, true, true, true, true, true, true, true); break; case 9: drawBars(g, xStart, yStart, true, true, true, true, false, false, true); break; } //System.out.println("I got to processDigit"); } public void processLine(Graphics g, int yStart, String subString) { for(int j = 0; j < 5; j++)//i THINK this method is correct... { char a = subString.charAt(j); int adigit = a - 48; int xStart = 30 + (30*j); processDigit(g, xStart, yStart, adigit); } //System.out.println("I got to processLine"); } public void processAllLines(Graphics g) // think this is right too { String t = ""; for(int j = 0; j < 3; j++) { t = num.substring(5*j, 5*j + 5); int yStart = 30 + (60*j); sum = sum + Integer.parseInt(t); processLine(g, yStart, t); } //System.out.println("I got processAllLines"); } public void line(Graphics g) { int xStart = 0; int yStart = 180; g.drawLine(xStart, yStart, 0, 180); //System.out.println("I got to line"); //need to code something to draw a straight line across from (0,180) to (180?,180) } public void processSum(Graphics g, int total) { int var = 0; if((total / 100000) >= 1)// if/else depending on whether the sum is 6 or 5 digits { for(int j = 5; j >= 0; j--) { var = (total / ((int)Math.pow(10,j))); total = (total % ((int)Math.pow(10,j))); int yStart = 210; int xStart = 30*(5-j); processDigit(g, xStart, yStart, var); } } else { for(int j = 4; j >= 0; j--) { var = (total / ((int)Math.pow(10,j))); total = (total % ((int)Math.pow(10,j))); int yStart = 210; int xStart = 30 + (30*(4-j)); processDigit(g, xStart, yStart, var); } } //System.out.println("I got to processSum"); } }

Comment