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

    Default ID Card Generator Help

    import java.awt.*;
    import javax.swing.*;
    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(; // 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.drawString("Name:" + firstName + " " + lastName, 250, 150);
    g.drawString("Department: " + department, 250, 200);
    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.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


    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() {

    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.

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

    (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
    Madgaon, Goa, India
    Rep Power

    Default Re: ID Card Generator Help

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

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