Results 1 to 4 of 4
- 03-16-2010, 10:37 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Using Scanner console for Graphics
Hey guys I'm relatively new to Java and i am using eclipse as a program for my college class.
I have an assignment where i have to use a Drawing panel of 400x400 and make a checkerboard (of 4 squares), which i have done relatively easy.
But the problem that I have now is what should come before that, the scanner console:
My program should prompt the user for a four letter word of their choice (which i've done), and then use a Scanner object to read in the four letter word from the console for each square in the painting. I then have to use String methods to convert the word to all uppercase and extract the individual letters.
Here is what i have so far, and i added the word love just so i could find out the letters positions:
import java.util.*;
import java.awt.*;
public class paintingLOVE {
public static void main(String[] args) {
System.out.println("Choose a four letter word of your choice:");
Scanner console = new Scanner(System.in);
String s = console.next();
DrawingPanel panel = new DrawingPanel(400, 400);
panel.setBackground (new Color (250, 80, 140));
Graphics g = panel.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, 200, 200);
g.setColor(Color.BLACK);
g.fillRect(200, 200, 200, 200);
g.setFont(new Font("Serif", Font.BOLD, 250));
g.setColor(Color.WHITE);
g.drawString("L", 25, 175);
g.setFont(new Font("Serif", Font.BOLD, 250));
g.setColor(Color.WHITE);
g.drawString("O", 205, 180);
g.setFont(new Font("Serif", Font.BOLD, 250));
g.setColor(Color.WHITE);
g.drawString("V", 11, 382);
g.setFont(new Font("Serif", Font.BOLD, 250));
g.setColor(Color.WHITE);
g.drawString("E", 220, 382);
}
}
-
I wouldn't advise mixing event-driven programming and console programming in this way. I think that you're far better off sticking with one or the other, in this case with event-driven programming, preferably Swing, not AWT. I'm not sure what a "DrawingPanel" is though.
- 03-17-2010, 02:05 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
I have to use Drawing Panel in the assignment for eclipse...
-
Unfortunately, this post doesn't help us help you much. Eclipse is an IDE and has nothing to do with your problem. You state that you're using DrawingPanel, but we already know this. You still need to tell us what the DrawingPanel class is -- is it a class that extends JPanel? Canvas? You still need to address the other issues in my previous post.
Similar Threads
-
How to get input from Console
By karma in forum New To JavaReplies: 8Last Post: 08-13-2010, 09:32 PM -
Console Progress Bar
By new_2_java in forum New To JavaReplies: 1Last Post: 02-16-2008, 02:18 AM -
Reading a line from console using Scanner class
By Java Tip in forum Java TipReplies: 0Last Post: 01-18-2008, 11:52 AM -
Console doesn't appear!
By PeteMarsh in forum New To JavaReplies: 2Last Post: 12-17-2007, 05:41 PM -
Read from console (Scanner Class)
By hey in forum New To JavaReplies: 10Last Post: 12-11-2007, 10:11 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks