Results 1 to 2 of 2
  1. #1
    werewolves12 is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default ID Card Generator Help

    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.*;
    import static java.lang.System.*;
    import java.awt.Font.*;

    class MainPanel extends JPanel {
    String firstName = new String();
    String lastName = new String();
    String department = new String();
    String age = new String();
    String idNumber = new String();

    public MainPanel(){
    Scanner kb = new Scanner(in);
    System.out.println("Welcome to the ID Card Maker.");
    System.out.println("What is your first name?");
    String firstName = kb.nextLine();
    System.out.println("What is your last name?");
    String lastName = kb.nextLine();
    System.out.println("What is your department?");
    String department = kb.nextLine();
    System.out.println("How old are you?");
    int age = kb.nextInt();

    idNumber = department.substring(0, 3) + lastName.length()*age + firstName.substring(0, 2) + lastName.substring(lastName.length()-2);

    }

    public void paintComponent(Graphics g) {
    g.setColor(Color.orange); // these lines of codes
    g.drawRect(0, 0, 800, 500); // sets the background of the
    g.fillRect(0, 0, 800, 800); // ID Card to the color orange.

    Font name;
    name = new Font("TimesNewRoman", Font.BOLD, 20);
    g.setColor(Color.red);
    g.setFont(name);
    g.drawString("Name:" + firstName + " " + lastName, 250, 150);
    g.setColor(Color.black);
    g.drawString("Department: " + department, 250, 200);
    g.setColor(Color.green);
    g.drawString("Age: " + age, 250, 250);



    /* Now use .length() & .substring() to display the information that is requested
    on the badge for the Identification in the correct location. */

    Font word;
    word = new Font("TimesNewRoman", Font.BOLD, 17);
    g.setColor(Color.black);
    g.setFont(word);
    g.drawString("ID Number:" + idNumber, 250, 50);




    /*here is yet another example of how to display the department starting at
    index 0 and ending at index 3
    g.drawString(dept.substring(0,3)*/




    }

    }
    public class Lab13a extends JFrame{

    public static void main(String[] args) {
    //This is a necessary in order to create the frame window
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    Lab13();
    }
    });
    }

    public static void Lab13() {

    //Sets up the frame
    JFrame frame = new JFrame("Graphics");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.getContentPane().setLayout(new BorderLayout());

    //Display the window.
    frame.pack();

    //Adds the graphics panel and sets the size
    frame.setSize(new Dimension(800,600));
    frame.getContentPane().add(new MainPanel(), BorderLayout.CENTER);
    frame.setVisible(true);
    }
    }






    (This is what I have so far, and I need help on getting the names, age, and department visible after I get the user's input.)
    I used JCreator for this.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: ID Card Generator Help

    Please confine beginner questions to the 'New to Java' section. I've moved this thread.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Question Card Layout, Card Management
    By lrichil in forum AWT / Swing
    Replies: 1
    Last Post: 04-22-2010, 11:11 AM
  2. please help me with this card game
    By noobinoo in forum New To Java
    Replies: 13
    Last Post: 03-28-2010, 03:07 PM
  3. Debit Card
    By dana180 in forum New To Java
    Replies: 1
    Last Post: 11-08-2009, 08:39 PM
  4. Card
    By hedonist in forum New To Java
    Replies: 3
    Last Post: 08-13-2009, 03:20 PM
  5. Card Layout
    By Gilbee in forum NetBeans
    Replies: 3
    Last Post: 03-03-2009, 10:37 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
  •