Simple code, but wrong, please help.

I wrote the follow code. When I call it in another class but no disaply. What happens? Please help me to correct it. Thanks.
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class tempStr extends JApplet{
final static Color bg = Color.white;
final static Color fg = Color.black;
String str;
tempStr(String string){
     str=string;
     JFrame f = new JFrame("string draw");
        JApplet applet1 = new tempStr(str);
        f.getContentPane().add("Center", applet1);
        applet1.init();
        f.pack();
       f.setSize(new Dimension(400,400));
        f.show();
    public void init() {
        setBackground(bg);
        setForeground(fg);
public void paint(Graphics g) {
  Graphics2D g2=(Graphics2D)g;
    g2.drawString(str, 40,160);
  }

It would be better to move the creation code into some dedicated method:
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class tempStr extends JApplet{
    final static Color bg = Color.white;
    final static Color fg = Color.black;
    String str;
    tempStr(String string){
        str=string;
    public void init() {
        setBackground(bg);
        setForeground(fg);
    public void paint(Graphics g) {
        Graphics2D g2=(Graphics2D)g;
        g2.drawString(str, 40,160);
    public static void main(String argv[]) {
        JFrame f = new JFrame("string draw");
        JApplet applet1 = new tempStr(argv[0]);
        f.getContentPane().add("Center", applet1);
        applet1.init();
        f.pack();
        f.setSize(new Dimension(400,400));
        f.show();
}To lauch the applet from command line:
java tempStr "Hello world"

Similar Messages

  • I am having trouble printing I have a connection to my printer wirelessly but does not print out the correct page I want.When I do print I get a bunch of pages more than is needed and also get a code and symbols please help I am jammed at work

    I am having trouble printing I have a connection to my printer wirelessly but does not print out the correct page I want.When I do print I get a bunch of pages more than is needed and also get a code and symbols please help I am jammed at work

    This can be the result of selecting the wrong driver. An older, unsupported laser printer will sometimes work with the generic Postscript driver.

  • How to install windows 7 on my macbook pro mid 2009 using usb. right now aim using mavericks 10.9 can any one please help me. I tried to edit plist in boot camp but it went wrong please help me

    how to install windows 7 on my macbook pro mid 2009 using usb. right now iam using mavericks 10.9 can any one please help me. I tried to edit plist in boot camp but it went wrong please help me.
    Iam new to coding. please help me.

    try the solution posted by kunu here and report back
    https://discussions.apple.com/thread/5105056?tstart=0

  • HT4113 When I go for restrictions my iPad mini want my pass code I fill it's recurarment it's say wrong please help me what I do....?

    When I go for restrictions my iPad mini want my pass code I fill it's recurarment it's say wrong please help me what I do....?

    Hey there Ajjusingh,
    It sounds like the passcode you are entering for your Restrictions is not working for you. According to the following article you will need to perform a factory restore to reset that passcode:
    iOS: Understanding Restrictions (parental controls)
    http://support.apple.com/kb/ht4213
    Note: If you lose or forget a restriction passcode, you will need to perform a factory restore to remove it.
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Hello sir i have IPhone 5 this imei is : ******** and i but my mail and password but the icloud tell me its wrong please help me my mail is : ********  and my password is ********

    hello sir i have IPhone 5 this imei is : ********** and i but my mail and password but the icloud tell me its wrong please help me my mail is : *********
    and my password is *******
    <Personal Information Edited by Host>

    You might try the following steps:
    Restart the device by holding down the on/off button until the power down slider appears.
    Try entering your password in another location (i.e. when you are using a different wifi network)
    Reset all settings (settings > general > reset), this resets some of your settings to factory default. It’s not a complete removal of settings. It removes all of your preferences for Wi-Fi, Bluetooth, Do No Disturb, Notifications, General, Sounds, Brightness & Wallpaper and Privacy. It does not remove any of your data.
    Try signing out of iCloud and back in (only if find my phone is disabled)
    If this doesn’t help your best option may be to contact Apple ID Support, upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.

  • When I download the digital copy of the Hunger Games, it stops at 4.0GB and first returns an error code -1309 and then the code -50. Please help me complete the download.

    When I download the digital copy of the Hunger Games, it stops at 4.0GB and first returns an error code -1309 and then the code -50. Please help me complete the download. I have tried removing the .tmp folder and downloading it again, but each time it stops the download in the same place.

    I discovered the solution. The external drive I was saving it to was formatted as FAT32. In that format, the largest files can only be 4GB, which explains why it kept stopping at 4GB. I backed up all the files then reformatted it as Mac OS Extended (Journaled), this is possible since I am on an iMac.

  • My compouter (PC) no longer recognizes my ipod (4th gen), it "sees" an unknowndevice and gives me error code 43.  Please help.

    My compouter (PC) no longer recognizes my ipod (4th gen), it "sees" an unknowndevice and gives me error code 43.  Please help.

    Check for hardware issues
    Try to restore your iOS device two more times while connected with a cable, computer, and network you know are good. Also, confirm your security software and settings are allowing communication between your device and update servers. If you still see the alert when you update or restore, contact Apple support.
    Common errors: 1, 10-47, 1002, 1011, 1012, 1014, 1000-1020.
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                      

  • Hello, i have a problem with this number code  213:19,  please help me!

    Hello, i have a problem with this number code  213:19,  please help me!

    dan
    What version of Premiere Elements and on what computer operating system is it running?
    If you are using Premiere Elements 13, have you updated it to 13.1 yet? If not, please do so using an opened project's Help Menu/Updates.
    What type of user account are you using....local administrator or domain type?
    Please review the following Adobe document on the 213.19 issue. Have you read that already?
    Error 213:19 | Problem has occurred with the licensing of this product
    ATR

  • I need to unlock compaq mini code is CNU027599F, please help

    i need to unlock compaq mini code is CNU027599F, please help
    This question was solved.
    View Solution.

    Ash try.
    e9l17xqoo8
    3rd letter lowercase L.
    4th is number 1.
    7th letter lowercase Q.
    8th and 9th letter lowercase O.
    Use that code to go into the BIOS.
    Disable all passwords that are enabled.
    IF asked for the CURRENT password use that code.
    IF asked for NEW password just hit enter.
    If asked to VERIFY password just hit enter.
    Save and exit.
    REO
    I must inform you that these services are not endorsed by HP, and that HP is not responsible for any damage that may arise to your system by using these services. Please be aware that you do this at your own risk.
    HP Expert Tester "Now testing HP Pavilion 15t i3-4030U Win8.1, 6GB RAM and 750GB HDD"
    Loaner Program”HP Split 13 x2 13r010dx i3-4012Y Win8.1, 4GB RAM and 500GB Hybrid HDD”
    Microsoft Registered Refurbisher
    Registered Microsoft Partner
    Apple Certified Macintosh Technician Certification in progress.

  • HT4759 I find the delete button on my iPhone and iPhone wrong goes wrong please help thanks

    I find the delete button on my iPhone and iPhone wrong goes wrong please help thanks

    Welcome to the user to User Technical Support Forum provided by Apple.
    Clearly state your Issue and the Troubleshooting Steps you have tried to Resolve it.

  • I get a lock bios code of 60293385 please help

    i get a lock bios code of 60293385 please help some times it is was a 5###### somthing?

    Post most recent code here:
    http://bios-pw.org/
    ******Clicking the Thumbs-Up button is a way to say -Thanks!.******
    **Click Accept as Solution on a Reply that solves your issue to help others**

  • Ask for help( simple code but wired error )!

    The post I sent just now has some mistakes. This post is correct. My simple code is as follows:
    import java.io.*;
    import java.net.*;
    public class count {
    float dclient = (float)3.333;
    float dlan = (float)0.01884;
    float drouter = (float)0.00115;
    float doutlink = (float)0.04185;
    float dinternet = (float)1.2615;
    float dinlink = (float)3.18129;
    float client1 = 0;
    float lan1 = 0;
    float router1 = 0;
    float outlink1 = 0;
    float internet1 = 0;
    float inlink1 = 0;
    float client2 = 0;
    float lan2 = 0;
    float router2 = 0;
    float outlink2 = 0;
    float internet2 = 0;
    float inlink2 = 0;
    float x = 0;
    float z = (float)3.333;
    public static void main(String[] args) {
    for (int n=1; n<16; ++n)
    client1 = dclient;
    lan1 = dlan * (1+lan2);
    router1 = drouter;
    outlink1 = doutlink * (1+outlink2);
    internet1 = dinternet;
    inlink1 = dinlink * (1+inlink2);
    x = n / (z + client1 + lan1 + router1 + outlink1 + internet1 + inlink1);
    client2 = x * client1;
    lan2 = x * lan1;
    rounter2 = x * rounter1;
    outlink2 = x * outlink1;
    internet2 = x * internet1;
    inlink2 = x * inlink1;
    System.out.println(client1 + " " +
    lan1 + " " +
    rounter1 + " " +
    outlink1 + " " +
    internet1+ " " +
    inlink1+ " **** " +
    x + " **** " +
    client2 + " " +
    lan2 + " " +
    rounter2 + " " +
    outlink2 + " " +
    internet2+ " " +
    inlink2 + " ********************end of n = " + n + "************************"
    The compiling error is:
    count.java:43: Can't make a static reference to nonstatic variable dclient in class count.
    client1 = dclient;
    ^
    1 error
    What is wrong with it? Many thanks!

    import java.io.*;
    import java.net.*;
    public class count
         public static float dclient = (float)3.333;
         public static float dlan = (float)0.01884;
         public static float drouter = (float)0.00115;
         public static float doutlink = (float)0.04185;
         public static float dinternet = (float)1.2615;
         public static float dinlink = (float)3.18129;
         public static float client1 = 0;
         public static float lan1 = 0;
         public static float router1 = 0;
         public static float outlink1 = 0;
         public static float internet1 = 0;
         public static float inlink1 = 0;
         public static float client2 = 0;
         public static float lan2 = 0;
         public static float router2 = 0;
         public static float outlink2 = 0;
         public static float internet2 = 0;
         public static float inlink2 = 0;
         public static float x = 0;
         public static float z = (float)3.333;
         public static void main(String[] args)
              for (int n=1; n<16; ++n)
                   client1 = dclient;
                   lan1 = dlan * (1+lan2);
                   router1 = drouter;
                   outlink1 = doutlink * (1+outlink2);
                   internet1 = dinternet;
                   inlink1 = dinlink * (1+inlink2);
                   x = n / (z + client1 + lan1 + router1 + outlink1 + internet1 + inlink1);
                   client2 = x * client1;
                   lan2 = x * lan1;
                   router2 = x * router1;
                   outlink2 = x * outlink1;
                   internet2 = x * internet1;
                   inlink2 = x * inlink1;
                   System.out.println(client1 + " " +     lan1 + " " router1 " " outlink1 " " internet1 " " inlink1 " **** " +     x + " **** " +
                   client2 + " " +
                   lan2 + " " +
                   router2 + " " +
                   outlink2 + " " +
                   internet2+ " " +
                   inlink2 + " ********************end of n = " + n + "************************"

  • Warning this is very long code but i need help to see if I am on right trac

    I have done all the following code myself and it is the buisiness layer for my application. I have tried to follow recommendations on previous posts and I would like to be told where I can clean up my code and how? This is not complete and it looks very long to me but I need help in order to be better. There are 4 button vlivks and I have not completed them all. The criteria for application is that phonebook will accept new entries if they have names surnames and phone numbers that are not longer than 10 characters for display purposes but can change this. No duplicates are allowed. No editing of a existing entry must lead to a duplicate entry either. No new entry or edit may result in a new contact having no phone numbers.
    Many thanks for your time in advance,.....
    import javax.swing.JOptionPane;
    import java.util.ArrayList;
    public class Contact
    {// Start of the Contact class
         ArrayList<ContactDetails> phoneList = new ArrayList<ContactDetails>();          // To hold all the contacts
         ArrayList<ContactDetails> searchList = new ArrayList<ContactDetails>();          // To hold all contacts that return true on search
         ArrayList<ContactDetails> list = new ArrayList<ContactDetails>();
         String newName;                                                                                // To hold the new name
         String newSurname;                                                                           // to hold the new surname
         String newHome;                                                                                // To hold the new home number if any
         String newWork;                                                                                // To hold the new work number
         String newCell;                                                                                // To hold the new cell number
         final int MAX_LENGTH = 10;
         public boolean addToPhoneList;                                                            // Sets to false if there is an invalid entry
         public boolean addToSearchList;                                                            // Sets to false if there is an invlid search
         public boolean modifyContact;                                                            // Sets to false if there is an invalid modification
         // Method to create a new contact
         public void createNew()
         {// Start of create new()
              addToPhoneList = true;                                                                 // Set boolean to true each time the method is executed
              getNewContactsName();                                                                 // Get new name
              if(addToPhoneList == false)
                   createNew();
                   return;
              getNewContactsSurname();                                                            //Get new surname
              if(addToPhoneList == false)
                   createNew();
                   return;
              String checkName = newName;                                                            //Creates copies to be used in the checkIfDuplicate method
              String checkSurname = newSurname;
              addToPhoneList = checkIfDuplicate(checkName, checkSurname);                    //Check if the entries are duplicate
              if(addToPhoneList == false)
                   createNew();
                   return;
              getNewContactsHomeNum();                                                            // Get new home number
              if(addToPhoneList == false)
                   createNew();
                   return;
              getNewContactsWorkNum();                                                            // Get new work number
              if(addToPhoneList == false)
                   createNew();
                   return;
              getNewContactsCellNum();                                                            // Get new cell number
              if(addToPhoneList == false)
                   createNew();
                   return;
              checkAtLeastOneNumEntered();                                                       // Check that at least one phone number was entered
              if(addToPhoneList == true)
                   updateListWithNew();
         }// End of createNew()
         // Method to search for an existing contact
         public void searchExisting()
         {// Start of searchExisting()
              addToSearchList = true;                                                                 // Set the boolean true
              searchList.clear();                                                                      // Clear list from any previous searches
              if(phoneList.size() > 0)                                                            // Check if any contacts are in the list
                   getExistingDetailsAndSearch();                                                  // If there are entries then continue to search
              else
                   JOptionPane.showMessageDialog(null,"There are no contacts to search for. Please use this option when you have added a contact to the list.","Error",JOptionPane.ERROR_MESSAGE);
         }// End of searchExisting()
         // Method to modify an existing contact
         public void modifyExisting()
         {// Start of modifyExisting()
              modifyContact = true;                                                                 // Set the boolean to true
              if(phoneList.size() <= 0)                                                            // Check if the phonelist is not empty
                   JOptionPane.showMessageDialog(null,"There are no contacts to modify. Please use this option when there have been contacts added to the list.","Error",JOptionPane.ERROR_MESSAGE);
              else
                   getExistingDetailsAndModify();                                                  // If phonelist not emty continue to modify method
         }// End of modifyExisting()
         //Method to delete a contact from the list
         public void deleteExisting()
         //Method to get new contacts name
         public void getNewContactsName()
              newName = JOptionPane.showInputDialog("Please enter the new contacts name or press cancel to exit without saving.");
              if(newName == null)
                   finish();
              if(newName.trim().length()<=0)
                   JOptionPane.showMessageDialog(null,"You have not entered a name. Please try again.","Error",JOptionPane.ERROR_MESSAGE);
                   addToPhoneList = false;
                   return;
              addToPhoneList = checkLengthValid(newName, "name");
         //Method to get a new contacts surname
         public void getNewContactsSurname()
              newSurname = JOptionPane.showInputDialog("Please enter the new contacts surnname or press cancel to exit without saving.");
              if(newSurname == null)
                   finish();
              addToPhoneList = checkLengthValid(newSurname, "surname");
         //Method to get a new contacts home number
         public void getNewContactsHomeNum()
              newHome = JOptionPane.showInputDialog("Please enter the new contacts home number or press cancel to exit without saving.");
              if(newHome == null)
                   finish();
              if(newHome.trim().length() > 0)
                   try
                        Long homeNum = Long.parseLong(newHome);
                   catch(Exception e)
                        JOptionPane.showMessageDialog(null,"You may only use numbers for a valid phone number. Please try again.","Error",JOptionPane.ERROR_MESSAGE);
                        addToPhoneList = false;
                        return;
              addToPhoneList = checkLengthValid(newHome, "home number");
         //Method to get a new contacst work number
         public void getNewContactsWorkNum()
              newWork = JOptionPane.showInputDialog("Please enter the new contacts work number or press cancel to exit without saving");
              if(newWork == null)
                   finish();
              if(newWork.trim().length()> 0)
                   try
                        Long workNum = Long.parseLong(newWork);
                   catch(Exception e)
                        JOptionPane.showMessageDialog(null,"You may only use numbers for a valid number. Please try again.","Error",JOptionPane.ERROR_MESSAGE);
                        addToPhoneList = false;
                        return;
              addToPhoneList = checkLengthValid(newWork, "work number");
         //Method to get a new contacts cell number
         public void getNewContactsCellNum()
              newCell = JOptionPane.showInputDialog("Please enter the new contacts cell number or press cancel to exit without saving");
              if(newCell == null)
                   finish();
              if(newCell.trim().length() > 0)
                   try
                        Long cellNum = Long.parseLong(newCell);
                   catch(Exception e)
                        JOptionPane.showMessageDialog(null,"You may only use numbers for a valid number. Please try again.","Error",JOptionPane.ERROR_MESSAGE);
                        addToPhoneList = false;
                        return;
              addToPhoneList = checkLengthValid(newCell, "cell number");
         //Method to get the details for an existing contact
         public void getExistingDetailsAndSearch()
              String existingName = getExistingName("search for");
              if(existingName == null)
                   addToSearchList = false;
                   return;
              if(existingName.length()<=0)
                   JOptionPane.showMessageDialog(null,"You have not entered a name please try again","Error",JOptionPane.ERROR_MESSAGE);
                   addToSearchList = false;
                   searchExisting();
              String existingSurname = getExistingSurname();
                   if(existingSurname == null)
                        return;
              if(addToSearchList == true)
                   searchAndAddIfFound(existingName, existingSurname);
         //Method to get existing details and modify contact
         public void getExistingDetailsAndModify()
              String existingName = getExistingName("modify");
              if(existingName == null)
                   modifyContact = false;
                   return;
              if(existingName.length()<=0)
                   JOptionPane.showMessageDialog(null,"You have not entered a name please try again","Error",JOptionPane.ERROR_MESSAGE);
                   modifyContact = false;
                   modifyExisting();
              String existingSurname = getExistingSurname();
                   if(existingSurname == null)
                        return;
              if(modifyContact == true)
                   getContactBySearch(existingName.trim().toUpperCase(), existingSurname.trim().toUpperCase());
         //Method to get the contact from list and modify details
         public void getContactBySearch(String currentName, String currentSurname)
              int count = 0;
              int numFound = 0;
              for(ContactDetails cd: phoneList)
                   cd = phoneList.get(count);
                   if((cd.name.equals(currentName))&&(cd.surname.equals(currentSurname)))
                        numFound ++;
                        changeDetails(cd);
                   count ++;
              if(numFound <= 0)
                   JOptionPane.showMessageDialog(null,"No contacts matching the name and surname you entered found. Press the modify button to try again.","Information",JOptionPane.INFORMATION_MESSAGE);
         //Method to get existing contacts name
         public String getExistingName(String whatWasClicked)
              String name = JOptionPane.showInputDialog("Please enter the contacts name that you wish to "+whatWasClicked);
              return name;
         //Method to get an existing contacts surname
         public String getExistingSurname()
              String surname = JOptionPane.showInputDialog("Please enter the contacts surname.");
              return surname;
         //Method to change the details of contact
         public void changeDetails(ContactDetails conToChange)
              String currentName = conToChange.name;
              String currentSurname = conToChange.surname;
              String currentHome = conToChange.home;
              String currentWork = conToChange.work;
              String currentCell = conToChange.cell;
              String newNameForContact = getNewModName(currentName);
              if(modifyContact == false)
                   modifyExisting();
                   return;
              String newSurnameForContact = getNewModSurname(currentSurname);
              if(modifyContact == false)
                   modifyExisting();
                   return;
              String newHomeForContact = getNewModHome(currentHome);
              if(modifyContact == false)
                   modifyExisting();
                   return;
              String newWorkForContact = getNewModWork(currentWork);
              if(modifyContact == false)
                   modifyExisting();
                   return;
              String newCellForContact = getNewModCell(currentCell);
              if(modifyContact == false)
                   modifyExisting();
                   return;
              if(modifyContact == true)
                   conToChange.name = newNameForContact;
         //Method to get the modified name
         public String getNewModName(String currentName)
              String newModifiedName = JOptionPane.showInputDialog("Please enter the new name for contact or press cancel to keep it as is.");
              if(newModifiedName == null)
                   return currentName;
              if(newModifiedName.trim().length() <= 0)
                   JOptionPane.showMessageDialog(null,"You may not replace the existing name with a blank name. Please try again.","Error",JOptionPane.ERROR_MESSAGE);
                   modifyContact = false;
                   return currentName;
              modifyContact = checkLengthValid(newModifiedName, "modified name");
              return newModifiedName;
         //Method to get the modified surname
         public String getNewModSurname(String currentSurname)
              String newModifiedSurname = JOptionPane.showInputDialog("Please enter the new surname for the contact or press cancel to keep it as is.");
              if(newModifiedSurname == null)
                   return currentSurname;
              modifyContact = checkLengthValid(newModifiedSurname, "modified surname");
              if(modifyContact == false)
                   JOptionPane.showMessageDialog(null,"Surname not changed.","Information",JOptionPane.INFORMATION_MESSAGE);
                   return currentSurname;
              modifyContact = checkLengthValid(newModifiedSurname, "modified surname");
              return newModifiedSurname;
         //Method to search and update the list with a succesfull search
         private void searchAndAddIfFound(String name, String surname)
              int count = 0;
              int numFound = 0;
              for(ContactDetails cd: phoneList)
                   cd = phoneList.get(count);
                   if(cd.name.equals(name.trim().toUpperCase()))
                        numFound ++;
                        searchList.add(cd);
                   count ++;
              if(numFound <= 0)
                   JOptionPane.showMessageDialog(null,"No contacts were found matching the dat you entered.","Information",JOptionPane.INFORMATION_MESSAGE);
              else
                   list.clear();
                   list.addAll(searchList);
         //Method that check all entries are a valid logical length
         //Method is based on assumption that a normal name, surname, and phone numbers are not longer than 10 characters long.
         //IF This method is changed please change the layout in the GUI as this is also set to fit with the layout that gives a neat //apperance
         private boolean checkLengthValid(String detailEntered, String whatWasEntered)
              boolean validLength = true;
              if(detailEntered.trim().length() >= MAX_LENGTH)
                   JOptionPane.showMessageDialog(null,"The " +whatWasEntered+" you entered is too long. Please try again and use a "+whatWasEntered+" that is less than "+MAX_LENGTH+" characters long.","Error",JOptionPane.ERROR_MESSAGE);
                   validLength = false;
              return validLength;
         private void finish()
              System.exit(0);
         //Method to update the list with a new entry
         private void updateListWithNew()
              try
                   ContactDetails cd = new ContactDetails();
                   cd.name = newName.trim().toUpperCase();
                   cd.surname = newSurname.trim().toUpperCase();
                   cd.home = newHome.trim();
                   cd.work = newWork.trim();
                   cd.cell = newCell.trim();
                   phoneList.add(cd);
                   JOptionPane.showMessageDialog(null,"Contact succesfully entered. To save this change press exit to save or use the save option in the toolbar menu.","Information",JOptionPane.INFORMATION_MESSAGE);
              catch(Exception e)
                   JOptionPane.showMessageDialog(null,"Failed to add contact to list. If problem persists please contact the software developer.","Error",JOptionPane.ERROR_MESSAGE);
              list.clear();
              list.addAll(phoneList);
         //Method to check for duplicate
         public boolean  checkIfDuplicate(String nameToCheck, String surnameToCheck)
              int count = 0;
              boolean valid = true;
              for(ContactDetails cd : phoneList)
                   cd = phoneList.get(count);
                   if(((nameToCheck.trim().toUpperCase()).equals(cd.name))&&((surnameToCheck.trim().toUpperCase()).equals(cd.surname)))
                        JOptionPane.showMessageDialog(null,"You may not enter a duplicate contact. Please try again and change the name and surname.","Error",JOptionPane.ERROR_MESSAGE);
                        valid = false;
                        break;
                   count ++;
              return valid;
         //Method to check that at least one phone number exists for contact
         public void checkAtLeastOneNumEntered()
              if((newHome.trim().length()<=0)&&(newWork.trim().length()<=0)&&(newCell.trim().length()<=0))
                   JOptionPane.showMessageDialog(null,"You have not entered any phone number at all. You must enter at least one phone number for a new contact.","Error",JOptionPane.ERROR_MESSAGE);
                   addToPhoneList = false;
         //Method that returns the list to the GUI
         public ArrayList<ContactDetails> getList()
              return list;
    }

    Should I start over from scratch? Can I get help with links to tutorials on following? How to create a java CRUD application (google not useful) and how to layer in java(google not useful)
    This is my pres layer as is is this wrong too?
         Filename:     ContactsListInterface.java
         Date:           16 March 2008
         Programmer:     Yucca Nel
         Purpose:     Provides a GUI for entering names and contact numbers into a telephone directory.
                        Also allows options for searching for a specific name and deleting of data from the record
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    public class Phonebook1 extends JFrame implements ActionListener
    { //start of class
         // construct fields, buttons, labels,text boxes, ArrayLists etc
         JTextPane displayPane = new JTextPane();
         JLabel listOfContacts = new JLabel("List Of Contacts");               // creates a label for the scrollpane
         JButton createButton = new JButton("Create");
         JButton searchButton = new JButton("Search");
         JButton modifyButton = new JButton("Modify");
         JButton deleteButton = new JButton("Delete");
         Contact c = new Contact();
         ArrayList<ContactDetails> contactList = c.getList();
         // create an instance of the ContactsListInterface
         public Phonebook1()
         { // start of cli()
              super("Phonebook Interface");
         } // end of cli()
         public JMenuBar createMenuBar()
         { // start of the createMenuBar()
              // construct and populate a menu bar
              JMenuBar mnuBar = new JMenuBar();                              // creates a menu bar
              setJMenuBar(mnuBar);
              JMenu mnuFile = new JMenu("File",true);                         // creates a file menu in the menu bar which is visible
                   mnuFile.setMnemonic(KeyEvent.VK_F);
                   mnuFile.setDisplayedMnemonicIndex(0);
                   mnuFile.setToolTipText("File Options");
                   mnuBar.add(mnuFile);
              JMenuItem mnuFileExit = new JMenuItem("Save And Exit");     // creates an exit option in the file menu
                   mnuFileExit.setMnemonic(KeyEvent.VK_X);
                   mnuFileExit.setDisplayedMnemonicIndex(1);
                   mnuFileExit.setToolTipText("Close Application");
                   mnuFile.add(mnuFileExit);
                   mnuFileExit.setActionCommand("Exit");
                   mnuFileExit.addActionListener(this);
              JMenu mnuEdit = new JMenu("Edit",true);                         // creates a menu for editing options
                   mnuEdit.setMnemonic(KeyEvent.VK_E);
                   mnuEdit.setDisplayedMnemonicIndex(0);
                   mnuEdit.setToolTipText("Edit Options");
                   mnuBar.add(mnuEdit);
              JMenu mnuEditSort = new JMenu("Sort",true);                    // creates an option for sorting entries
                   mnuEditSort.setMnemonic(KeyEvent.VK_S);
                   mnuEditSort.setDisplayedMnemonicIndex(0);
                   mnuEdit.add(mnuEditSort);
              JMenuItem mnuEditSortByName = new JMenuItem("Sort By Name");          // to sort entries by name
                   mnuEditSortByName.setMnemonic(KeyEvent.VK_N);
                   mnuEditSortByName.setDisplayedMnemonicIndex(8);
                   mnuEditSortByName.setToolTipText("Sort entries by first name");
                   mnuEditSortByName.setActionCommand("Name");
                   mnuEditSortByName.addActionListener(this);
                   mnuEditSort.add(mnuEditSortByName);
              JMenuItem mnuEditSortBySurname = new JMenuItem("Sort By Surname");     // to sort entries by surname
                   mnuEditSortBySurname.setMnemonic(KeyEvent.VK_R);
                   mnuEditSortBySurname.setDisplayedMnemonicIndex(10);
                   mnuEditSortBySurname.setToolTipText("Sort entries by surname");
                   mnuEditSortBySurname.setActionCommand("Surname");
                   mnuEditSortBySurname.addActionListener(this);
                   mnuEditSort.add(mnuEditSortBySurname);
              JMenu mnuHelp = new JMenu("Help",true);                                        // creates a menu for help options
                   mnuHelp.setMnemonic(KeyEvent.VK_H);
                   mnuHelp.setDisplayedMnemonicIndex(0);
                   mnuHelp.setToolTipText("Help options");
                   mnuBar.add(mnuHelp);
              JMenuItem mnuHelpHelp = new JMenuItem("Help");                              // creates a help option for help topic
                   mnuHelpHelp.setMnemonic(KeyEvent.VK_P);
                   mnuHelpHelp.setDisplayedMnemonicIndex(3);
                   mnuHelpHelp.setToolTipText("Help Topic");
                   mnuHelpHelp.setActionCommand("Help");
                   mnuHelpHelp.addActionListener(this);
                   mnuHelp.add(mnuHelpHelp);
              JMenuItem mnuHelpAbout = new JMenuItem("About");                         // creates a about option for info about api
                   mnuHelpAbout.setMnemonic(KeyEvent.VK_T);
                   mnuHelpAbout.setDisplayedMnemonicIndex(4);
                   mnuHelpAbout.setToolTipText("About this program");
                   mnuHelpAbout.setActionCommand("About");
                   mnuHelpAbout.addActionListener(this);
                   mnuHelp.add(mnuHelpAbout);
              return mnuBar;
         } // end of the createMenuBar()
         // create the content pane
         public Container createContentPane()
         { // start of createContentPane()
              //construct and populate panels and content pane
              JPanel labelPanel = new JPanel(); // panel is only used to put the label for the textpane in
                   labelPanel.setLayout(new FlowLayout());
                   labelPanel.add(listOfContacts);
              JPanel displayPanel = new JPanel();// panel is used to display all the contacts and thier numbers
                   setTabsAndStyles(displayPane);
                   displayPane = addTextToTextPane();
                   displayPane.setEditable(false);
              JScrollPane scrollPane = new JScrollPane(displayPane);
                   scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // pane is scrollable vertically
                   scrollPane.setWheelScrollingEnabled(true);// pane is scrollable by use of the mouse wheel
                   scrollPane.setPreferredSize(new Dimension(400,320));
              displayPanel.add(scrollPane);
              JPanel workPanel = new JPanel();// panel is used to enter, edit and delete data
                   workPanel.setLayout(new FlowLayout());
                   workPanel.add(createButton);
                        createButton.setToolTipText("Create a new entry");
                        createButton.addActionListener(this);
                   workPanel.add(searchButton);
                        searchButton.setToolTipText("Search for an entry by name number or surname");
                        searchButton.addActionListener(this);
                   workPanel.add(modifyButton);
                        modifyButton.setToolTipText("Modify an existing entry");
                        modifyButton.addActionListener(this);
                   workPanel.add(deleteButton);
                        deleteButton.setToolTipText("Delete an existing entry");
                        deleteButton.addActionListener(this);
              labelPanel.setBackground(Color.red);
              displayPanel.setBackground(Color.red);
              workPanel.setBackground(Color.red);
              // create container and set attributes
              Container c = getContentPane();
                   c.setLayout(new BorderLayout(30,30));
                   c.add(labelPanel,BorderLayout.NORTH);
                   c.add(displayPanel,BorderLayout.CENTER);
                   c.add(workPanel,BorderLayout.SOUTH);
                   c.setBackground(Color.red);
              // add a listener for the window closing and save
              addWindowListener(
                   new WindowAdapter()
                        public void windowClosing(WindowEvent e)
                             int answer = JOptionPane.showConfirmDialog(null,"Are you sure you would like to save all changes and exit?","File submission",JOptionPane.YES_NO_OPTION);
                             if(answer == JOptionPane.YES_OPTION)
                                  System.exit(0);
              return c;
         } // end of createContentPane()
         protected void setTabsAndStyles(JTextPane displayPane)
         { // Start of setTabsAndStyles()
              // set Font style
              Style fontStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
              Style regular = displayPane.addStyle("regular", fontStyle);
              StyleConstants.setFontFamily(fontStyle, "SansSerif");
              Style s = displayPane.addStyle("bold", regular);
              StyleConstants.setBold(s,true);
         } // End of setTabsAndStyles()
         public JTextPane addTextToTextPane()
         { // start of addTextToTextPane()
              int numberOfEntries = contactList.size();
              int count = 0;
              Document doc = displayPane.getDocument();
              try
              { // start of tryblock
                   // clear previous text
                   doc.remove(0,doc.getLength());
                   // insert titles of columns
                   doc.insertString(0,"NAME\tSURNAME\tHOME NO\tWORK NO\tCELL NO\n",displayPane.getStyle("bold"));
                   for(ContactDetails cd : contactList)
                        cd = contactList.get(count);
                        doc.insertString(doc.getLength(),cd.name+"\t"+cd.surname+"\t"+cd.home+"\t"+cd.work+"\t"+cd.cell+"\n",displayPane.getStyle("regular"));
                        count ++;
              } // end of try block
              catch(BadLocationException ble)
              { // start of ble exception handler
                   System.err.println("Could not insert text.");
              } // end of ble exception handler
              return displayPane;
         } // end of addTextToTextPane()
         // code to process user clicks
         public void actionPerformed(ActionEvent e)
         { // start of actionPerformed()
              String arg = e.getActionCommand();
              // user clicks create button
              if(arg.equals("Create"))
                   c.createNew();                                                  // method to create a new Contact
                   addTextToTextPane();
              if(arg.equals("Search"))
                   c.searchExisting();                                             // method to search for an existing entry
                   addTextToTextPane();
              if(arg.equals("Modify"))
                   c.modifyExisting();                                             // method to modify contact
                   addTextToTextPane();
              if(arg.equals("Delete"))
                   c.deleteExisting();
                   addTextToTextPane();
              if(arg.equals("Exit"))
         } // end of actionPerformed()
         // method to create a new contact
         public static void main(String[] args)
         { // start of main()
              // Set look and feel of interface
              try
              { // start of try block
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              } // end of try block
              catch(Exception e)
              { // start of catch block
                   JOptionPane.showMessageDialog(null,"There was an error in setting the look and feel of this application","Error",JOptionPane.INFORMATION_MESSAGE);
              } // end  of catch block
              Phonebook1 pb = new Phonebook1();
              pb.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
              pb.setJMenuBar(pb.createMenuBar());
              pb.setContentPane(pb.createContentPane());
              pb.setSize(520,500);
              pb.setVisible(true);
              pb.setResizable(false);
         } // end of main()
    } //end of class

  • HTMLB Code not working Please help.....

    Hello All,
    Ive new in HTMLB. Have written this code wherein a JSP page is called from a JSPDynPage file. But am <b>not getting any output. Its all blank.</b> Dunno if im going wrong .... Please help.
    Struggling with this since y'day.
    <b>CODE</b>:
    <u><b>UserInfoDynPage.java</b></u>
    package com.sap.sample;
    import com.sapportals.htmlb.*;
    import com.sapportals.htmlb.enum.*;
    import com.sapportals.htmlb.event.*;
    import com.sapportals.htmlb.page.*;
    import com.sapportals.portal.htmlb.page.*;
    import com.sapportals.portal.prt.component.*;
    public class UserInfoDynPage extends PageProcessorComponent
    {     public DynPage getPage()
         {     return new UserInfoDynPageDynPage();
           public static class UserInfoDynPageDynPage extends JSPDynPage
           {     //private UserInfoBean UserInfoBean = null;
             public void doInitialization()
             {          IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
                       IPortalComponentSession componentSession = ((IPortalComponentRequest)getRequest()).getComponentSession();
                    /*Object o = componentSession.getValue("UserInfoBean");
                    if(o==null || !(o instanceof UserInfoBean))
                    {     UserInfoBean = new UserInfoBean();
                      componentSession.putValue("UserInfoBean",UserInfoBean);
                    else
                    {     UserInfoBean = (UserInfoBean) o;
                    // fill your bean with data here...
        public void doProcessAfterInput() throws PageException
        public void doProcessBeforeOutput() throws PageException
        {     this.setJspName("UserInfo.jsp");
    <u><b>UserInfo.jsp</b></u>
    <%@ taglib uri="tagLib" prefix="hjb" %>
    <hbj:content id="myContext" >
         <hbj:page title="UserInfo Page">
            <hbj:form id="myFormId" >
                 <hbj:textView id="title" text="Search Screen" design="STANDARD" />
                 <table>
                      <tr>
                           <td>
                                <hbj:label id:"lb_Search" text"Search For" labelFor="search" />
                           </td>
                           <td>
                                <hbj:inputField id="search" type="string" maxlength="25" />
                           </td>
                      </tr>
                      <tr>
                           <td>
                                <hbj:label id="lb_SearchType" text="Search Type" labelFor="searchType" />
                           </td>
                           <td>
                                <hbj:dropdownListBox id="SearchType" tooltip="UME Object  to search for" disabled="false">
                                     <hbj:listBoxItem key="user" value="User" />
                                     <hbj:listBoxItem key="group" value="Group" />
                                     <hbj:listBoxItem key="role" value="Role" />
                                </hbj:dropdownListBox>
                           </td>
                      </tr>
                 </table>
                 <br>
                 <hbj:button id="submit" text"search!" tooltip="Click me to search" disabled="false" design="emphasized" />
                 <br>
                 <br>
       </hbj:form>
      </hbj:page>
    </hbj:content>
    <u><b>Portalapp.xml</b></u>
    <?xml version="1.0" encoding="utf-8"?>
    <application>
      <application-config>
        <property name="PrivateSharingReference" value="com.sap.portal.htmlb"/>
      </application-config>
      <components>
        <component name="UserInfoDynPage">
          <component-config>
            <property name="ClassName" value="com.sap.sample.UserInfoDynPage"/>
            <property name="ComponentType" value="jspnative"/>
            <property name="JSP" value="pagelet/UserInfo.jsp"/>
          </component-config>
          <component-profile>
               <property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>
          </component-profile>     
        </component>
      </components>
      <services/>
    </application>
    =============
    Please help.
    Awaiting Reply.
    Thanks,
    Uday
    Message was edited by: Uday Hardikar

    Hi BHI,
    Thank you for your input.
    Had made silly mistake and got solved.
    And now, I have another problem which is related to this same program but the error seems to be a different one.
    Have posted another query:
    Error in HTMLB program..Please help..Urgent OR Error in HTMLB program..Please help..Urgent
    Please help me as its kinda urgent.
    Thanks in advance.
    Uday

  • Mystery Problem in Code...Please Help...

    Ok, here's the situation. I am a photographer, and have been writing code for some time now. I decided to write a java application that would write individual web pages for each jpeg present in two directories, bnw and color, making the job of writing as many as 300 virtually identical pages a lot less annoying. Unfortunately, this is even more so.
    The code is clean in nice, and it compiles without a hitch. When I run the application (w/ jdk 1.4.0) on Windows 98, it comes up with an invalid path error when it tries to create the first of these web pages, but after it writes the list of all the images it sees. (This list is created successfully.) I went back and double checked that there weren't any filenames that Windows would gripe about, and an error was found. I corrected the error, and now everything is kosher, but yet the same error still occurs. I've several different methods of doing the same thing, and every time, the same error occurs at the same spot. I have included the source code below. Please, any help would be appreciated!
    import java.io.*;
    import java.util.*;
    public class listDir {
         public static final String DEBUG = true;
         static {
              if (DEBUG)
                   System.err.println("----------- < DEBUGGING IS ON > -------------");
            public static void main(String[] args) {
              // DEBUG STATEMENT
              System.err.print("DEBUG: Declaring final Strings... ");
                    final String path1 = "E:\\Liam Conrad - Photographer\\800x600\\images\\html\\bnw";
                    final String path2 = "E:\\Liam Conrad - Photographer\\800x600\\images\\html\\color";
              final String line1 = "<html>\r\n<head>\r\n<title></title>\r\n<link href=\"../../master.css\" rel=\"stylesheet\">\r\n</head>\r\n";
              final String line2 = "<body>\r\n<table width=\"100%\" height=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\r\n<tr>\r\n";
              final String line3 = "<td align=\"center\" valign=\"top\" colspan=\"1\" width=\"100%\">\r\n<p><img src=\"";
              final String line4 = "\" border=\"1\" width=\"432\" height=\"288\" alt=\"\"></p></td></tr></table></body></html>\r\n\r\n\r\n";
              // DEBUG STATEMENT (2)
              System.err.println("[ DONE ]");
              System.err.print("DEBUG: Declaring variables... ");
              String temps1;
              String temps2;
                    RandomAccessFile raf;
                    RandomAccessFile mfo;
                    File d1;
                    File d2;
                    String[] list1;
                    String[] list2;
                    String[] list3;
                    Vector svect = new Vector();
              // DEBUG STATEMENT (2)
              System.err.println("[ DONE ]");
              System.err.println("DEBUG: Beginning try statement.");
                    try {
                            d1 = new File(path1);
                            d2 = new File(path2);
                            raf = new RandomAccessFile("dirlist.txt", "rw");
                            list1 = d1.list();
                            list2 = d2.list();
                            for (int i = 0; i < list1.length; i++) {
                                    if (list1.endsWith(".jpg")) {
    svect.add("bnw_" + list1[i]);
    } else {
    for (int i = 0; i < list2.length; i++) {
    if (list2[i].endsWith(".jpg")) {
    svect.add("color_" + list2[i]);
    } else {
    for (int i = 0; i < svect.size(); i++) {
    raf.writeBytes((i+1) + ":\t" + svect.get(i) + "\r\n");
    raf.close();
                   for (int i = 0; i < svect.size(); i++) {
                        temps1 = svect.get(i) + "\b\b\bhtml";
                        temps2 = temps1;
                        System.out.println(temps2);
                        mfo = new RandomAccessFile(temps2, "rw"); // <--- Here is where the error is occuring every time.
                        mfo.writeBytes(line1);
                        mfo.writeBytes(line2);
                        mfo.writeBytes(line3);
                        mfo.writeBytes((String)svect.get(i));
                        mfo.writeBytes(line4);
                        mfo.close();
    } catch (Exception e) {
    e.printStackTrace();
                   System.err.println((char)7 + "\n");

    Hi buddy
    First of all, there is no mystery in this program. Everything is pretty clear...
    OK, Instead of pointing out the mistakes you have done, I thought why not may be I cam modify the program and then give u the code. Go thru the code and you will understand the mistakes you have done. You have to make a few changes to make this applicable to you. Firstly, change the directory names, secondly, change the GIFs to JPGs, thirdly, add the table formatting that you were looking for(i removed the formatting for simplicity)... and things like that.
    Lot of things to say about : Since you are creating a html file in the current directory and in that html file, you are refering to the images in two other directories, you wont be able to see the images unless you move the files to the current working directory. And you cannot move a file from one directory to another using Java IO(Only way is you can create exact replicas of the files in other directories). Or, One way to get around with this problem is : Use full path of the file instead of just the name of the GIF(or jpeg or whatever) file. That is what I have done in the following program.
    Cheers
    -Uday
    import java.io.*;
    import java.util.*;
    public class Picture {
         public static final boolean DEBUG = true;
         static {
              if (DEBUG)
                   System.err.println("----------- < DEBUGGING IS ON > -------------");
    public static void main(String[] args) {
              // DEBUG STATEMENT
              System.err.print("DEBUG: Declaring final Strings... ");
    final String path1 = "C:\\uday\\PIC\\one";
    final String path2 = "C:\\uday\\PIC\\two";
              final String line1 = "<html>\r\n<head>\r\n<title></title>\r\n</head>\r\n";
              final String line2 = "<body>\r\n<table>\r\n<tr>\r\n";
              final String line3 = "<td align=\"center\" valign=\"top\">\r\n<p><img src=\"";
              final String line4 = "\" alt=\"\"></p></td></tr></table></body></html>\r\n\r\n\r\n";
              // DEBUG STATEMENT (2)
              System.err.println("[ DONE ]");
              System.err.print("DEBUG: Declaring variables... ");
              String temps1;
              String temps2;
    RandomAccessFile raf;
    RandomAccessFile mfo;
    File d1;
    File d2;
    String[] list1;
    String[] list2;
    String[] list3;
    Vector svect = new Vector();
              Vector nvect = new Vector();
              // DEBUG STATEMENT (2)
              System.err.println("[ DONE ]");
              System.err.println("DEBUG: Beginning try statement.");
    try {
    d1 = new File(path1);
    d2 = new File(path2);
    raf = new RandomAccessFile("dirlist.txt", "rw");
    list1 = d1.list();
    list2 = d2.list();
    for (int i = 0; i < list1.length; i++) {
    if (list1.endsWith(".gif")) {
                             nvect.add(path1+"\\"+list1[i]);
                             String temp1 = "one_"+list1[i].substring(0,list1[i].lastIndexOf(".gif"));
    svect.add(temp1);
    } else {
    for (int i = 0; i < list2.length; i++) {
    if (list2[i].endsWith(".gif")) {
                             nvect.add(path2+"\\"+list2[i]);
                             String temp2 = "two_"+list2[i].substring(0,list2[i].lastIndexOf(".gif"));
    svect.add(temp2);
    } else {
    for (int i = 0; i < svect.size(); i++) {
    raf.writeBytes((i+1) + ":\t" + svect.get(i) + "\r\n");
    raf.close();
                   for (int i = 0; i < svect.size(); i++) {
                        temps1 = svect.get(i) + ".html";
                        temps2 = temps1;
                        System.out.println(temps2);
                        mfo = new RandomAccessFile(temps2, "rw"); // <--- Here is where the error is
    occuring every time.
                        mfo.writeBytes(line1);
                        mfo.writeBytes(line2);
                        mfo.writeBytes(line3);
                        mfo.writeBytes((String)nvect.get(i));
                        mfo.writeBytes(line4);
                        mfo.close();
    } catch (Exception e) {
    e.printStackTrace();
                   System.err.println((char)7 + "\n");

Maybe you are looking for

  • Multiple Select options

    Hi, I have a requirement where i have to use to separate select options but the value of the 2nd Select option is dependant of the value chosen in the first select option. For eg:First Select option is for SWCV and 2nd option is for Data Object. If y

  • How to move the contents of an itab from one class to another...

    Hello Experts, How can I move the contents of an internal table for a given class to another class. I want to transfer the contents of my internal table lt_vbak to another class which is lcl_get_docflow. Below is my code: REPORT  zsd_orderstage      

  • How do you eject a hard drive?

    How do you eject an external hard drive?

  • [solved] [radeon] HDMI audio stopped working, video too fast

    I'm using the `xf86-video-ati` driver, which worked fine up until when I upgraded Arch, after some weeks of not doing so. Now the HDMI audio is silent. Also, when I set the audio to output to HDMI in the GNOME sound menu, videos are playing faster. I

  • How to get GUID in DO_INIT method

    Hi All, I have a requirement to default the CC mail id's when a follow up email is created from complaint i am trying to acheive this by redefining DO_INIT method and created a new method set_CCmailid where i am trying to call order_read to get the p