Results 1 to 4 of 4
  1. #1
    bensewards is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default 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);

    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    bensewards is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default

    I have to use Drawing Panel in the assignment for eclipse...

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by bensewards View Post
    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

  1. How to get input from Console
    By karma in forum New To Java
    Replies: 8
    Last Post: 08-13-2010, 10:32 PM
  2. Console Progress Bar
    By new_2_java in forum New To Java
    Replies: 1
    Last Post: 02-16-2008, 03:18 AM
  3. Reading a line from console using Scanner class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-18-2008, 12:52 PM
  4. Console doesn't appear!
    By PeteMarsh in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 06:41 PM
  5. Read from console (Scanner Class)
    By hey in forum New To Java
    Replies: 10
    Last Post: 12-11-2007, 11:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •