Help with drawing strings on JFrame?!?!

Hey guys, I'm really new to Java (just started AP Comp Sci last month), and we had a project to build a Mastermind application using numbers, which I did. However, I'm trying to learn more on my own, and was hoping to use the example code my teacher gave me to output what I want to say to a JFrame instead of just the command prompt.
Here is the code for my Mastermind class:
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Mastermind extends JFrame
     public static void main(String args[])
          int master[] = new int[4];
          int win = 0;
          for(int x = 0; x<4; x++)
               master[x] = (int)(Math.random()*10);
          System.out.println();
          do {
               int guess[] = new int[4];
               int countMaster[] = new int[4];
          String numguess = JOptionPane.showInputDialog("Enter your guess (4 digits, please)");
          for (int x = 0;x<4;x++)
               guess[x] = (numguess.charAt(x)-48);
          int correctlyPlaced = 0;
          int correct = 0;
          for (int x = 0;x<4;x++)
               if(master[x] == guess[x])
                    correctlyPlaced += 1;
          for (int x = 0; x<4;x++)
                         for (int y = 0; y<4;y++)
                              if((guess[x]==master[y]) && (countMaster[y]==0)) {
                                   correct++;
                                   countMaster[y]=1;
                                   y=5;
          System.out.print("Guess:\t\t\t");
          for (int x = 0;x<4;x++) {
               System.out.print(guess[x]);
          System.out.println();
          System.out.println("Correct:\t\t"+correct);
          System.out.println("Correctly Placed:\t"+correctlyPlaced);
          if (correctlyPlaced==4) {
               win=1;
     } while(win<1);
     System.out.println("You win!");
          System.exit(0);
And here is the example code that my teacher gave me for how to draw a string on a JFrame:
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Fonts extends JFrame {
     public Fonts()
          super("Using Fonts");
          setSize(420,125);
          show();
     public void paint(Graphics g)
          super.paint(g);
          g.setFont(new Font("Serif", Font.BOLD, 12));
          g.drawString("Serif 12 point bold.",20,50);
     public static void main(String args[])
          Fonts application = new Fonts();
          application.setDefaultCloseOperation (
               JFrame.EXIT_ON_CLOSE);
I would like to be able to put "Guess," "Correct," and "Correctly Placed," on a JFrame, with their respective variables. Any ideas? Thank you!!!

800045 wrote:
And DrClap, I get that, but I'm not sure how to put my existing code into the class file that uses the JFrame.You wouldn't put your existing code in there. Your existing code is designed to run as a console app and most of it is concerned with the machinery of getting input from the user. If you want to write it as a Swing app, then you wouldn't need any code which writes to a JFrame in the first place.
So if your goal for learning on your own is to write GUI applications instead of console applications, then go off and read the Swing tutorials. Right now you're going down the wrong road. However if you're trying to learn something else on your own (I can't tell what that might be) then explain what it is you're trying to learn.

Similar Messages

  • Need help with drawing shape and scrollbar

    Hi everybody, I am newbie at java just started learning it. I have a few questions to ask.
    1. Can anyone show me to how to draw a equilateral penatgon, octagon, ( 5-10 sized shape) with polar cordinate.
    2. How to make the scrollbar back to their default state( work alone not together) after you use the "scrollbar1.setModel(scrollbar2.getModel())" method. For example I only want the scrollbar to work together when I choose circle as a shape after that I want the scrollbar to be back to normal when I pick another shape rectangle for example. When the scrollbar work together, how do I the make it so that the scrollbar move from bottom to top for vertical bar and from left to right for the horizontal bar when they work together instead of the default bar move from left(0) to right(max) for horizontal bar and from top(0) to bottom(max) for the vertical bar.

    Here's some code that builds regular polygonal icons.
    import java.awt.*;
    import javax.swing.*;
    class PolygonIcon implements Icon
         protected int height, width;
         protected int iheight, iwidth;
         protected int left, top, xc, yc, diam, idiam;
         protected Color background, foreground;
         protected double fract;
         protected int sides;
         protected int[] xp;
         protected int[] yp;
         PolygonIcon(int h, int w,  Color fc, Color bc, double fr, int s, boolean sym )
              sides = s;
              // save constructor args
              width = w;
              height = h;
              foreground = fc;
              background = bc;
              fract = fr;
              // define basic geometry
              diam = (width<height)?width:height;     // diameter
              xc = width/2;                              // x centre
              yc = height/2;                              // y centre
              int border = (int)(diam*.5*(1-fract));     // size of border
              idiam = diam-(border+border);                    // icon diameter
              if(sym)                                        // symetric case
                   top = (height-idiam)/2;               // top offset
                   left = (width-idiam)/2;               // left offset
                   iheight = idiam;                    // image height
                   iwidth = idiam;                         // image width
              else                                        // assymetric case
                   top = border;                         // top offset
                   left = border;                         // left offset
                   iwidth = width-(left+left);          // image width
                   iheight = height -(top+top);     // image height
              double srad = Math.toRadians(360.0/sides);
              int xs, ys;
              if(sym)xs = ys = diam/2;
              else
                   xs = iwidth/2;
                   ys = iheight/2;
              xp = new int[sides];
              yp = new int[sides];
              double rad;
              for(int i = 0; i<sides; i++)
                   rad = srad*i;
                   xp[i] = xc+(int)(Math.sin(rad)*xs);
                   yp[i] = yc+(int)(Math.cos(rad)*ys);
         // set colors
         public void setForeground(Color fg){foreground = fg;}
         public void setBackground(Color bg){background = bg;}
         // methods required for Icon interface
         public int getIconWidth(){return width;}
         public int getIconHeight(){return height;}
         public void paintIcon(Component c, Graphics g, int x, int y)
              if(background != null  && c.isEnabled())
                   g.setColor(background);
                   g.fillRect(x,y,x+width,y+height);
              if(foreground != null)
                   int [] xn = new int[sides];
                   int [] yn = new int[sides];
                   for(int i = 0; i<sides; i++)
                        xn[i] = x+xp;
                        yn[i] = y+yp[i];
                   Polygon p = new Polygon(xn,yn,sides);
                   g.setColor(foreground);
                   g.fillPolygon(p);
    and an example of their use
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TestI extends JFrame
         TestI()
              addWindowListener(new WindowAdapter()
              {public void windowClosing(WindowEvent evt){System.exit(0);}});
              JLabel lbl1 = new JLabel(new PolygonIcon(50,100,Color.RED,Color.YELLOW,.90,6,true));
              JLabel lbl2 = new JLabel(new PolygonIcon(150,80,Color.BLUE,Color.GREEN,.75,8,true));
              JLabel lbl3 = new JLabel(new PolygonIcon(150,80,Color.BLUE,Color.GREEN,.75,3,false));
              Container cp = getContentPane();
              cp.setLayout(new FlowLayout());
              cp.add(lbl1);
              cp.add(lbl2);
              cp.add(lbl3);
              pack();
         public static void main(String[] args)
              new TestI().show();

  • Java Graphics -- Drawing Strings on JFrame

    Hello and thank you. I'm relatively young and I apologize for asking noob questions. The problem I am having is that I realized after 3 hours of research and then writing this code that when multiple JPanels are added to a JFrame, they overlap (I think) over each other. As a result, the output of this program below is at the bottom right of the frame, the number 841 appears (the last number in my array) and everything else is blank.
    And I could not at all understand how to create graphics objects. It kept giving me an error of not being able to be instantiated. And to be honest, I don't even really understand whats going on when I add the text to my JPanel. I never call paintComponents. And definately I could never even make a graphics object to provide it the parameter required. Anyway, I resolved to use Jpanels because they can be removed using the remove function of the JFrame. And It is vitally important that I can delete the strings off my frame. Here is my code:
    package main;
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    public class VisualFrame extends JFrame{
        ArrayList<JPanel> numbers = new ArrayList<JPanel>();
        public VisualFrame(){
            setSize(1000, 500);
            setTitle("Binary Search");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        public void createPanels(int[] array){
            int x = 10;
            int y = 20;
            int xOffset = 50;
            int yOffset = 50;
            for(int i=0; i<array.length; i++){
                String num = Integer.toString(array);
    numPanel panel = new numPanel(num, x, y);
    numbers.add(panel);
    add(panel);
    x = x+xOffset;
    if(x>this.getWidth()){
    x = 10;
    y = y+yOffset;
    class numPanel extends JPanel{
    String num;
    int x;
    int y;
    public numPanel(String str, int x, int y){
    num = str;
    this.x = x;
    this.y = y;
    public void paintComponent(Graphics g){
    g.setColor(Color.black);
    g.setFont(new Font("Times", Font.BOLD, 12));
    g.drawString(num, x, y);
    My main method is inside of a different class:
        public static void main(String[] args){
            VisualFrame frame = new VisualFrame();
            frame.createPanels(array);
        }Firstly, do I even have the problem I'm having right? If so,
    Is there a way to restrict the size of the panels to the length and width of what it contains?
    Or can someone give me a good, very detailed link to how to use Graphics? Or perhaps someone could prove to me a good method.
    Edited by: 989946 on Mar 8, 2013 6:45 PM

    Why don't you start by learning from the experts?
    The Java Tutorial has sections that show how to use Java functionality.
    http://docs.oracle.com/javase/tutorial/
    The Graphiics section covers GUI and Swing
    http://docs.oracle.com/javase/tutorial/uiswing/index.html
    >
    Creating Graphical User Interfaces
    Creating a GUI with Swing — A comprehensive introduction to GUI creation on the Java platform.
    >
    And that section has links for trails such as how to use ALL of the different swing components including frames and panels
    http://docs.oracle.com/javase/tutorial/uiswing/components/index.html
    >
    Using Swing Components tells you how to use each of the Swing components — buttons, tables, text components, and all the rest. It also tells you how to use borders and icons.

  • Need Help with a String Binary Tree

    Hi, I need the code to build a binary tree with string values as the nodes....i also need the code to insert, find, delete, print the nodes in the binarry tree
    plssss... someone pls help me on this
    here is my code now:
    // TreeApp.java
    // demonstrates binary tree
    // to run this program: C>java TreeApp
    import java.io.*; // for I/O
    import java.util.*; // for Stack class
    import java.lang.Integer; // for parseInt()
    class Node
         //public int iData; // data item (key)
         public String iData;
         public double dData; // data item
         public Node leftChild; // this node's left child
         public Node rightChild; // this node's right child
         public void displayNode() // display ourself
              System.out.print('{');
              System.out.print(iData);
              System.out.print(", ");
              System.out.print(dData);
              System.out.print("} ");
    } // end class Node
    class Tree
         private Node root; // first node of tree
         public Tree() // constructor
         { root = null; } // no nodes in tree yet
         public Node find(int key) // find node with given key
         {                           // (assumes non-empty tree)
              Node current = root; // start at root
              while(current.iData != key) // while no match,
                   if(key < current.iData) // go left?
                        current = current.leftChild;
                   else // or go right?
                        current = current.rightChild;
                   if(current == null) // if no child,
                        return null; // didn't find it
              return current; // found it
         } // end find()
         public Node recfind(int key, Node cur)
              if (cur == null) return null;
              else if (key < cur.iData) return(recfind(key, cur.leftChild));
              else if (key > cur.iData) return (recfind(key, cur.rightChild));
              else return(cur);
         public Node find2(int key)
              return recfind(key, root);
    public void insert(int id, double dd)
    Node newNode = new Node(); // make new node
    newNode.iData = id; // insert data
    newNode.dData = dd;
    if(root==null) // no node in root
    root = newNode;
    else // root occupied
    Node current = root; // start at root
    Node parent;
    while(true) // (exits internally)
    parent = current;
    if(id < current.iData) // go left?
    current = current.leftChild;
    if(current == null) // if end of the line,
    {                 // insert on left
    parent.leftChild = newNode;
    return;
    } // end if go left
    else // or go right?
    current = current.rightChild;
    if(current == null) // if end of the line
    {                 // insert on right
    parent.rightChild = newNode;
    return;
    } // end else go right
    } // end while
    } // end else not root
    } // end insert()
    public void insert(String id, double dd)
         Node newNode = new Node(); // make new node
         newNode.iData = id; // insert data
         newNode.dData = dd;
         if(root==null) // no node in root
              root = newNode;
         else // root occupied
              Node current = root; // start at root
              Node parent;
              while(true) // (exits internally)
                   parent = current;
                   //if(id < current.iData) // go left?
                   if(id.compareTo(current.iData)>0)
                        current = current.leftChild;
                        if(current == null) // if end of the line,
                        {                 // insert on left
                             parent.leftChild = newNode;
                             return;
                   } // end if go left
                   else // or go right?
                        current = current.rightChild;
                        if(current == null) // if end of the line
                        {                 // insert on right
                             parent.rightChild = newNode;
                             return;
                   } // end else go right
              } // end while
         } // end else not root
    } // end insert()
         public Node betterinsert(int id, double dd)
              // No duplicates allowed
              Node return_val = null;
              if(root==null) {       // no node in root
                   Node newNode = new Node(); // make new node
                   newNode.iData = id; // insert data
                   newNode.dData = dd;
                   root = newNode;
                   return_val = root;
              else // root occupied
                   Node current = root; // start at root
                   Node parent;
                   while(current != null)
                        parent = current;
                        if(id < current.iData) // go left?
                             current = current.leftChild;
                             if(current == null) // if end of the line,
                             {                 // insert on left
                                  Node newNode = new Node(); // make new node
                                  newNode.iData = id; // insert data
                                  newNode.dData = dd;
                                  return_val = newNode;
                                  parent.leftChild = newNode;
                        } // end if go left
                        else if (id > current.iData) // or go right?
                             current = current.rightChild;
                             if(current == null) // if end of the line
                             {                 // insert on right
                                  Node newNode = new Node(); // make new node
                                  newNode.iData = id; // insert data
                                  newNode.dData = dd;
                                  return_val = newNode;
                                  parent.rightChild = newNode;
                        } // end else go right
                        else current = null; // duplicate found
                   } // end while
              } // end else not root
              return return_val;
         } // end insert()
         public boolean delete(int key) // delete node with given key
              if (root == null) return false;
              Node current = root;
              Node parent = root;
              boolean isLeftChild = true;
              while(current.iData != key) // search for node
                   parent = current;
                   if(key < current.iData) // go left?
                        isLeftChild = true;
                        current = current.leftChild;
                   else // or go right?
                        isLeftChild = false;
                        current = current.rightChild;
                   if(current == null)
                        return false; // didn't find it
              } // end while
              // found node to delete
              // if no children, simply delete it
              if(current.leftChild==null &&
                   current.rightChild==null)
                   if(current == root) // if root,
                        root = null; // tree is empty
                   else if(isLeftChild)
                        parent.leftChild = null; // disconnect
                   else // from parent
                        parent.rightChild = null;
              // if no right child, replace with left subtree
              else if(current.rightChild==null)
                   if(current == root)
                        root = current.leftChild;
                   else if(isLeftChild)
                        parent.leftChild = current.leftChild;
                   else
                        parent.rightChild = current.leftChild;
              // if no left child, replace with right subtree
              else if(current.leftChild==null)
                   if(current == root)
                        root = current.rightChild;
                   else if(isLeftChild)
                        parent.leftChild = current.rightChild;
                   else
                        parent.rightChild = current.rightChild;
                   else // two children, so replace with inorder successor
                        // get successor of node to delete (current)
                        Node successor = getSuccessor(current);
                        // connect parent of current to successor instead
                        if(current == root)
                             root = successor;
                        else if(isLeftChild)
                             parent.leftChild = successor;
                        else
                             parent.rightChild = successor;
                        // connect successor to current's left child
                        successor.leftChild = current.leftChild;
                        // successor.rightChild = current.rightChild; done in getSucessor
                   } // end else two children
              return true;
         } // end delete()
         // returns node with next-highest value after delNode
         // goes to right child, then right child's left descendents
         private Node getSuccessor(Node delNode)
              Node successorParent = delNode;
              Node successor = delNode;
              Node current = delNode.rightChild; // go to right child
              while(current != null) // until no more
              {                                 // left children,
                   successorParent = successor;
                   successor = current;
                   current = current.leftChild; // go to left child
              // if successor not
              if(successor != delNode.rightChild) // right child,
              {                                 // make connections
                   successorParent.leftChild = successor.rightChild;
                   successor.rightChild = delNode.rightChild;
              return successor;
         public void traverse(int traverseType)
              switch(traverseType)
              case 1: System.out.print("\nPreorder traversal: ");
                   preOrder(root);
                   break;
              case 2: System.out.print("\nInorder traversal: ");
                   inOrder(root);
                   break;
              case 3: System.out.print("\nPostorder traversal: ");
                   postOrder(root);
                   break;
              System.out.println();
         private void preOrder(Node localRoot)
              if(localRoot != null)
                   localRoot.displayNode();
                   preOrder(localRoot.leftChild);
                   preOrder(localRoot.rightChild);
         private void inOrder(Node localRoot)
              if(localRoot != null)
                   inOrder(localRoot.leftChild);
                   localRoot.displayNode();
                   inOrder(localRoot.rightChild);
         private void postOrder(Node localRoot)
              if(localRoot != null)
                   postOrder(localRoot.leftChild);
                   postOrder(localRoot.rightChild);
                   localRoot.displayNode();
         public void displayTree()
              Stack globalStack = new Stack();
              globalStack.push(root);
              int nBlanks = 32;
              boolean isRowEmpty = false;
              System.out.println(
              while(isRowEmpty==false)
                   Stack localStack = new Stack();
                   isRowEmpty = true;
                   for(int j=0; j<nBlanks; j++)
                        System.out.print(' ');
                   while(globalStack.isEmpty()==false)
                        Node temp = (Node)globalStack.pop();
                        if(temp != null)
                             System.out.print(temp.iData);
                             localStack.push(temp.leftChild);
                             localStack.push(temp.rightChild);
                             if(temp.leftChild != null ||
                                  temp.rightChild != null)
                                  isRowEmpty = false;
                        else
                             System.out.print("--");
                             localStack.push(null);
                             localStack.push(null);
                        for(int j=0; j<nBlanks*2-2; j++)
                             System.out.print(' ');
                   } // end while globalStack not empty
                   System.out.println();
                   nBlanks /= 2;
                   while(localStack.isEmpty()==false)
                        globalStack.push( localStack.pop() );
              } // end while isRowEmpty is false
              System.out.println(
         } // end displayTree()
    } // end class Tree
    class TreeApp
         public static void main(String[] args) throws IOException
              int value;
              double val1;
              String Line,Term;
              BufferedReader input;
              input = new BufferedReader (new FileReader ("one.txt"));
              Tree theTree = new Tree();
         val1=0.1;
         while ((Line = input.readLine()) != null)
              Term=Line;
              //val1=Integer.parseInt{Term};
              val1=val1+1;
              //theTree.insert(Line, val1+0.1);
              val1++;
              System.out.println(Line);
              System.out.println(val1);          
    theTree.insert(50, 1.5);
    theTree.insert(25, 1.2);
    theTree.insert(75, 1.7);
    theTree.insert(12, 1.5);
    theTree.insert(37, 1.2);
    theTree.insert(43, 1.7);
    theTree.insert(30, 1.5);
    theTree.insert(33, 1.2);
    theTree.insert(87, 1.7);
    theTree.insert(93, 1.5);
    theTree.insert(97, 1.5);
              theTree.insert(50, 1.5);
              theTree.insert(25, 1.2);
              theTree.insert(75, 1.7);
              theTree.insert(12, 1.5);
              theTree.insert(37, 1.2);
              theTree.insert(43, 1.7);
              theTree.insert(30, 1.5);
              theTree.insert(33, 1.2);
              theTree.insert(87, 1.7);
              theTree.insert(93, 1.5);
              theTree.insert(97, 1.5);
              while(true)
                   putText("Enter first letter of ");
                   putText("show, insert, find, delete, or traverse: ");
                   int choice = getChar();
                   switch(choice)
                   case 's':
                        theTree.displayTree();
                        break;
                   case 'i':
                        putText("Enter value to insert: ");
                        value = getInt();
                        theTree.insert(value, value + 0.9);
                        break;
                   case 'f':
                        putText("Enter value to find: ");
                        value = getInt();
                        Node found = theTree.find(value);
                        if(found != null)
                             putText("Found: ");
                             found.displayNode();
                             putText("\n");
                        else
                             putText("Could not find " + value + '\n');
                        break;
                   case 'd':
                        putText("Enter value to delete: ");
                        value = getInt();
                        boolean didDelete = theTree.delete(value);
                        if(didDelete)
                             putText("Deleted " + value + '\n');
                        else
                             putText("Could not delete " + value + '\n');
                        break;
                   case 't':
                        putText("Enter type 1, 2 or 3: ");
                        value = getInt();
                        theTree.traverse(value);
                        break;
                   default:
                        putText("Invalid entry\n");
                   } // end switch
              } // end while
         } // end main()
         public static void putText(String s)
              System.out.print(s);
              System.out.flush();
         public static String getString() throws IOException
              InputStreamReader isr = new InputStreamReader(System.in);
              BufferedReader br = new BufferedReader(isr);
              String s = br.readLine();
              return s;
         public static char getChar() throws IOException
              String s = getString();
              return s.charAt(0);
         public static int getInt() throws IOException
              String s = getString();
              return Integer.parseInt(s);
    } // end class TreeApp

    String str = "Hello";
              int index = 0, len = 0;
              len = str.length();
              while(index < len) {
                   System.out.println(str.charAt(index));
                   index++;
              }

  • Help with comparing string array with parameters

    I've posted my code in full so hopefully everyone can see exactly what I have been doing.
    Note - my code uses the observer/observable model. The method I am having the problem with the if statement is in the class HSBC.
    Basically when the pin count reaches 4 (in the atm class) it sends the userid & pincode) over to the checkPinAndUserId(String pinCode, String userCode) method. Here the if statement should check the userid to see if the string parameter matches a string in the array. If it does it should check in the same position in the pin array to check the pin no is correct and then return true.
    * @(#)BankAssignment.java 1.0 03/04/06
    * This apllication l
    package myprojects.bankassignment;
    import java.awt.*; // import the component library
    import java.awt.event.*; // import the evnet library
    import javax.swing.*;
    import java.util.*;
    class Correct1v16 extends Frame // make a new application
         public Correct1v16() // this is the constructor method
              HSBC HSBCobj = new HSBC();
         public static void main(String args[]) // this invokes the constructor of the class and creates a runable object 'mainframe'
              Correct1v16 mainFrame = new Correct1v16(); // the constructor call of the class which creates an object of that class
    class HSBC implements Observer,  ActionListener
              Frame f5;
              JLabel refill, launch;
              TextField tRefill, tLaunch;
              JButton refillbut, launchbut;
              int count;
              String [] userId=new String [10];
              String [] pin=new String [10];
              public boolean authenticate = false;
              int i;
                   public HSBC()
                   drawFrame();
                   Atm Atmobj = new Atm(this);
                   System.out.println("Starting HSBC constructor");     
              public void drawFrame()
                   System.out.println("Start HSBC drawframe method...");
                   f5=new Frame("HSBC");
                   f5.setLayout(new FlowLayout());
                   f5.setSize(200, 200);
                   f5.addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)     
                             f5.dispose();
                             System.exit(0);     
                   refill=new JLabel("Refill ATM");
                   launch=new JLabel("Launch new ATM");
                   tRefill=new TextField(20);
                   tLaunch=new TextField(10);
                   refillbut=new JButton("Refill ATM");
                   refillbut.addActionListener(this);
                   launchbut=new JButton("Launch new ATM");
                   launchbut.addActionListener(this);
                   f5.add(refill);
                   f5.add(tRefill);
                   f5.add(refillbut);
                   f5.add(launch);
                   f5.add(tLaunch);
                   f5.add(launchbut);
                   f5.setVisible(true);
    //*********** POPULATE THE ARRAYS     */
                   pin[0]="1234";
                   pin[1]="2345";
                   pin[2]="3456";
                   pin[3]="4567";
                   pin[4]="5678";
                   pin[5]="6789";
                   pin[6]="7890";
                   pin[7]="8901";
                   pin[8]="9012";
                   pin[9]="0123";
                   userId[0]="0";
                   userId[1]="1";
                   userId[2]="2";
                   userId[3]="3";
                   userId[4]="4";
                   userId[5]="5";
                   userId[6]="6";
                   userId[7]="7";
                   userId[8]="8";
                   userId[9]="9";
              }// end drawframe method
              //     public Atm atmLink = (Atm)o;
                   public void update(Observable gm1, Object o)
                        Atm atmLink = (Atm)o;
                        tRefill.setText("Refill ATM ?");
                        atmLink.refill();
                   }//end update method
                   public void actionPerformed(ActionEvent ae)
                        if(ae.getSource() == refillbut)
    //                         Atm Atmobj.refill();
                        //     tRefill.setText("text area");     
                        //     atmLink.refill();
    //                         Atmobj.refill();
    //                         setChanged();
    //                         notifyObservers();
                        if(ae.getSource() == launchbut)
                             tLaunch.setText("new ATM opened");
                             Atm Atmobj1 = new Atm(this);
    //******** THIS METHOD RECEIVES THE PARAMETERS FROM THE ATM METHOD (LINE 580) (PINCODE AND USERCODE) BUT
    //******** IT ONLY THE ARRAY CALLED USERID (WHICH HOLDS THE USER CODE MATCHES ONE OF THE USERID'S)
    //******** I DO WANT IT TO DO THIS BUT I ALSO WANT IT TO MOVE ON AND CHECK THE PINCODE WITH THE PIN ARRAY)
    //******** IF THEY ARE BOTH TRUE I WANT IT TO RETURN TRUE - ELSE FALSE.          */               
                   public boolean checkPinAndUserId(String userCode, String pinCode)
                        boolean found = false;
                        System.out.println("in checkpin method");
                        System.out.println("userCode = "+ userCode);
                        System.out.println("pinCode = " + pinCode);
                        for (int i = 0; i < userId.length; i++)
                        System.out.println("in the userid array" + userId);
                             if (userCode.equals(userId[i]))
                                  System.out.println("checking user code array");
                                  if (pinCode.equals(pin[i]))
                                       System.out.println("checking the pin array" + pinCode);
                                       System.out.println("pin[i] = "+pin[i]);
                                  found = true;
                        return found;
         }// end HSBC class
    class Atm extends Observable implements ActionListener
              Frame f1;
              TextField t3, t5;
              JTextArea display = new JTextArea("Welcome to HSBC Bank. \n Please enter your User Identification number \n", 5, 40);
              JPanel p1, p2, p3,p4;
              private JButton but1, but2, but3, but4,but5,but6,but7,but8,but9,but0,enter,
              cancel,fivepounds,tenpounds,twentypounds,fiftypounds,clearbut, refillbut;
              int state = 1;                                        
              public String pinCode ="";
              public      String userCode ="";
              int userCodeCount = 0;
              int PINCount = 0;
              String withdrawAmount = "";
              int atmBalance =200;
              private HSBC HSBCobj;     
              //ATM constructor that receives the HSBCobj g1 reference to where the HSBC class
              // in in the program
              // Calls the drawATMFrame method
              // add the observer to the HSBCobj reference so that the ATM can tell HSBC that
              // something has changed
              public Atm(HSBC g1)
                   HSBCobj = g1;
                   drawATMFrame();
                   System.out.println("Starting Atm constructor");
                   addObserver(HSBCobj);     
              // this is the method that draws the ATM interface
              // also apply the Border Layout to the frame
              public void drawATMFrame()
                   f1=new Frame("ATM");
                   f1.setLayout(new BorderLayout());
                   f1.setSize(350, 250);
                   f1.addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)     
                             f1.dispose();
                             System.exit(0);     
                   // declare & instantiate all the buttons that will be used on the ATM
                   but1 =new JButton("1");
                   but1.addActionListener(this);
                   but2 =new JButton("2");
                   but2.addActionListener(this);
                   but3 =new JButton("3");
                   but3.addActionListener(this);
                   but4 =new JButton("4");
                   but4.addActionListener(this);
                   but5 =new JButton("5");
                   but5.addActionListener(this);
                   but6 =new JButton("6");
                   but6.addActionListener(this);
                   but7 =new JButton("7");
                   but7.addActionListener(this);
                   but8 =new JButton("8");
                   but8.addActionListener(this);
                   but9 =new JButton("9");
                   but9.addActionListener(this);
                   but0 =new JButton("0");
                   but0.addActionListener(this);
                   enter=new JButton("Enter");
                   enter.addActionListener(this);
                   cancel=new JButton("Cancel/ \n Restart");
                   cancel.addActionListener(this);
                   fivepounds =new JButton("?5");
                   fivepounds.addActionListener(this);
                   tenpounds = new JButton("?10");
                   tenpounds.addActionListener(this);
                   twentypounds = new JButton("?20");
                   twentypounds.addActionListener(this);
                   fiftypounds = new JButton("?50");
                   fiftypounds.addActionListener(this);
                   clearbut = new JButton("Clear");
                   clearbut.addActionListener(this);
                   refillbut = new JButton("Refill");
                   refillbut.addActionListener(this);
                   //declare & instantiate a textfield               
                   t3=new TextField(5);
                   // instantiate 4 JPanels     
                   p1=new JPanel();
                   p2=new JPanel();
                   p3=new JPanel();
                   p4=new JPanel();
                   // add some buttons to p1
                   p1.add(but1);
                   p1.add(but2);
                   p1.add(but3);
                   p1.add(but4);
                   p1.add(but5);
                   p1.add(but6);
                   p1.add(but7);
                   p1.add(but8);
                   p1.add(but9);               
                   p1.add(but0);
                   //add the text area field to p2
                   p2.add(display);
                   // apply the grid layout to p3
                   GridLayout layout3 = new GridLayout(4,1,5,5);
                   p3.setLayout(layout3);
                   p3.add(fivepounds);
                   p3.add(tenpounds);
                   p3.add(twentypounds);
                   p3.add(fiftypounds);
                   // apply grid layout to p4
                   GridLayout layout4 = new GridLayout(4,1,5, 5);
                   p4.setLayout(layout4);
                   p4.add(clearbut);
                   p4.add(enter);
                   p4.add(cancel);
                   p4.add(refillbut);
                   //add the panels to the different parts of the screen
                   f1.add("North", display);
                   f1.add("Center", p1);
                   f1.add("East", p4);
                   f1.add("West", p3);
                   f1.setVisible(true);
              }// end drawATMframe method
         public void actionPerformed(ActionEvent ae)
                   if(state == 1)
                             getUserIdNo(ae);
              else     if(state == 2)
                             doPINInput(ae);
                        else
                             withdrawCash(ae);     
         }// end action performed method               
    //******** STATE 1 events*/
    //******** USER ID INPUT*/
              public void getUserIdNo (ActionEvent ae)
                   if (ae.getSource() == but1)
                        display.append("*");
                        userCode = userCode + "1";
                        userCodeCount++;
                   if (ae.getSource() == but2)
                        display.append("*");
                        userCode = userCode + "2";
                        userCodeCount++;
                   if (ae.getSource() == but3)
                        display.append("*");
                        userCode = userCode + "3";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but4)
                        display.append("*");
                        userCode = userCode = "4";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but5)
                        display.append("*");
                        userCode = userCode + "5";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but6)
                        display.append("*");
                        userCode = userCode + "6";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but7)
                        display.append("*");
                        userCode = userCode + "7";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but8)
                        display.append("*");
                        userCode = userCode + "8";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but9)
                        display.append("*");
                        userCode = userCode + "9";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but0)
                        display.append("*");
                        userCode = userCode + "0";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == cancel)
                        display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                        userCode = "";
                        state = 2;
                   if (ae.getSource() == clearbut)
                        display.setText("Please enter your user ID number again\n");
                        userCode = "";
                        userCodeCount = 0;
                   if (ae.getSource() == refillbut)
                        refill();
                   if (ae.getSource() == enter)
                        display.setText("Please enter your PIN \n");
                        state = 2;
                        System.out.println(" User id enter button = " + userCode);
                   if (userCodeCount == 1)
                        display.setText("Please enter your PIN \n");
                        //userCode = "";
                        userCodeCount = 0;
                        state = 2;          
    //******** STATE 2               */
    //******** PIN INPUT*/
                   public void doPINInput(ActionEvent ae)
                        if (ae.getSource() == but1)
                             {      pinCode = pinCode.concat("1");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but2)
                             {      pinCode = pinCode.concat("2");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but3)
                             {      pinCode = pinCode.concat("3");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but4)
                             {      pinCode = pinCode.concat("4");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but5)
                             {      pinCode = pinCode.concat("5");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but6)
                             {      pinCode = pinCode.concat("6");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but7)
                             {      pinCode = pinCode.concat("7");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but8)
                             {      pinCode = pinCode.concat("8");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but9)
                             {      pinCode = pinCode.concat("9");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but0)
                             {      pinCode = pinCode.concat("0");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == clearbut)
                                  display.setText("Please enter your PIN number again \n");
                                  pinCode = "";     
                                  PINCount = 0;
                        if (ae.getSource() == cancel)
                                  display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                             state = 1;
                                  pinCode ="";
                                  PINCount = 0;                         
                        if (ae.getSource() == refillbut)
                                  refill();
    /// ************************ THIS BUTTON SENDS THE PIN & USER CODE OVER TO THE MAIN BANK*/
    /// ************************ (LINE 152)               */
                        if (ae.getSource() == enter)
    //                         if(HSBCobj.checkPinAndUserId(pinCode, userCode))
    //                              display.setText("How much would you like to withdraw \n");
    //                    else
    //                         display.setText("Your UserId and Pin code do not match");
                        if(PINCount ==4)
                        if(HSBCobj.checkPinAndUserId(userCode,pinCode))
                                  display.setText("Enter the amount you \n want to withdraw \n ?");
                                  PINCount=0;
                        else
                        display.setText("Your User Identification Number \n and PIN number do not match! \n please try again\n");     
    //*********** STATE 3 events*/
    //*********** withdrawCash*/
         public void withdrawCash(ActionEvent ae)
    //               if (ae.getSource() == but1)
    //                    display.append("1");
    ///                    withdrawAmount = withdrawAmount+1;
         //               pinCode = pinCode.concat("2");
         //               System.out.println("Withdrawal Amount = "+withdrawAmount);
                   if(ae.getSource( ) == but1)
                        withdrawAmount = withdrawAmount + "1";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but2)
                        withdrawAmount = withdrawAmount + "2";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but3)
                        withdrawAmount = withdrawAmount + "3";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but4)
                        withdrawAmount = withdrawAmount + "4";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but5)
                        withdrawAmount = withdrawAmount + "5";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but6)
                        withdrawAmount = withdrawAmount + "6";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but7)
                        withdrawAmount = withdrawAmount + "7";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but8)
                        withdrawAmount = withdrawAmount + "8";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but9)
                        withdrawAmount = withdrawAmount + "9";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but0)
                        withdrawAmount = withdrawAmount + "0";
                        display.setText(withdrawAmount);
                   if (ae.getSource() == fivepounds)
                        withdrawAmount = withdrawAmount + "5";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == tenpounds)
                        withdrawAmount = withdrawAmount + "10";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == twentypounds)
                        withdrawAmount = withdrawAmount + "20";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == fiftypounds)
                        withdrawAmount = withdrawAmount + "50";
                        display.setText(withdrawAmount);
                        atmBalance();
         //          if (ae.getSource() == tenpounds)
         //               display.append("10");
         //               withdrawAmount = 10;
         //               pinCode = pinCode.concat("2");
         //               System.out.println("10 pound button pressed");
         //               atmBalance();
                   if (ae.getSource() == enter)
                        atmBalance();
                   if (ae.getSource() == refillbut)
                        System.out.println("refill but pressed");
                        refill();     
                   if (ae.getSource() == clearbut)
                        System.out.println("clear but pressed");
                        display.setText("Enter the amount you want to withdraw \n ?");
                        withdrawAmount="";
                   if (ae.getSource() == cancel)
                        display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                        withdrawAmount="";
                   pinCode ="";
                        PINCount = 0;
                        userCode = "";
                        userCodeCount = 0;
                        state = 1;
         }// end withdraw cash input method
         // checks balace of atm and withdraws cash. Also notifies onserver if atm balance is low     
              public void atmBalance()
                   String s = withdrawAmount;
                   int n = Integer.parseInt(s);
                   if ( atmBalance >= n)
                        atmBalance = atmBalance - n;
                        System.out.println("atm balance = "+ atmBalance);
                        display.setText("Thankyou for using HSBC. \nYou have withdrawn ?"+n);
                        if     (atmBalance<40)
                             System.out.println("atm balance is less than 40 - notify HSBC" );
                             setChanged();
                             notifyObservers(this);
                             /// note the refil should send a message to the controller
                             // advising a refil is needed. The Bank will send an engineer
                             // out who will fill the atm up
              }// end atmBalance method
              /// note the refil should send a message to the controller
              /// then th coontroller will send a message to this method to fill machine
              /// (this is simulating a clerk filling atm)
                   public void refill()
                        System.out.println("in refill method" );
                        atmBalance = 200;
                        System.out.println("Atm has been refilled. Atm balance = " + atmBalance);
                   //     setChanged();
                   //     notifyObservers(this);
                   }// end refill method
    // NOTE SURE ABOUT THIS - DO I USE THE UPDATE METHOD TO NOTIFY HSBC THAT ATM REQUIRES FILLING
    // THIS IS THE WRONG PART OF THE PROGRAM (SHOULD BE IN HSBC) - IGNORE
                   public void update(Observable gm1, Object gameObj)
                        display.setText("Congratulations");               
                   }//end update method
         }// end Atm method
    }// end Assignment2 clas
    [\code]

    I wasn't trying to annoy anyone at all.
    I'm new to java and have been told that using the observer/observable model is not considered basic java. So that is the only reason I posted it in this section. At the same time i feel that the bit I'm struggling with is actually basic - hence posting it in the basic section. I'm not sure if people of all abilities check all forums or just the ones they feel at at their standard.
    So appologies if you've taken offence.

  • Need help with Drawing applet

    im in the process of making a network whiteboard as a project for college and i was wondering if anyone could help me with a problem im having. When my application minimises or a window is placed over the application the drawing is erased, even if a window is placed over a certain part of the application it erases the part it covers is there any way to stop this from happening i cant seem to fix it, any help is appreciated, thanks

    You should be buffering what the whiteboard is to draw, either as a BufferedImage or in some
    data structure so that you can refresh when asked to repaint. Are you doing that, or are you
    just drawing new graphics as it arrives from the server?

  • Still Need Help with this String Problem

    basically, i need to create a program where I input 5 words and then the program outputs the number of unique words and the words themselves. for example, if i input the word hello 5 times, then the output is 1 unique word and the word "hello". i have been agonizing over this dumb problem for days, i know how to do it using hashmap, but this is an introductory course and we cannot use more complex java functions, does ANYONE know how to do this just using arrays, strings, for loops, if clauses, etc. really basic java stuff. i want the code to be able to do what the following program does:
    import java.io.*; import java.util.ArrayList;
        public class MoreUnique {
           public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[] = new String[5]; int uniqueEntries = 0; ArrayList<String> ue = new ArrayList<String>();
             for (int i = 0; i < 5; i++) { System.out.print((i +1) + ": "); str[i] = br.readLine(); }
             for (int j = 0; j < 5; j++) {
                if (!ue.contains(str[j].toLowerCase())) { ue.add(str[j].toLowerCase()); } } uniqueEntries = ue.size(); System.out.print("Number of unique entries: " + uniqueEntries + " { ");
             for (int q = 0; q < ue.size(); q++ ) { System.out.print(ue.get(q) + " "); } System.out.println("}"); } } but i need to find how to do it so all 5 words are put in at once on one line, and without all the advanced java functions that are in here, can anyone help out?

    you have to compare string 0 to strings 1-4, then
    string 1 with strings 2-4, then string 2 with strings
    3 and 4 then string 3 with string 4....right???Here's a way to do it:
    public class MoreUnique {
        public static void main(String[] args) throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            final int NUM_WORDS = 5;
            String[] words = new String[NUM_WORDS];
            int uniqueEntries = 0;
            for(int i = 0; i < NUM_WORDS; i++) {
                System.out.print((i+1)+": ");
                String temp = br.readLine();
                if(!contains(temp, words)) {
                    words[uniqueEntries++] = temp;
            System.out.print("Number of unique entries: "+uniqueEntries+" { ");   
            for (int i = 0; i < uniqueEntries; i++ ) {   
                System.out.print(words[i]+" ");
            System.out.println("}");
        private static boolean contains(String word, String[] array) {
                 Your code here: just a simple for-statement to
                 loop through your array and to see if 'word'
                 is in your 'array'.
    }Try to fill in the blanks.
    Good luck.

  • I just upgraded to CP 5. Need help with drawing objects.

    I am trying to put a simple drawing object around a word.  Like a square.  I can't figure out how to not have any fill, just the outline of the box.  Any suggestions?  I was able to do this in CP 4.

    Hi there
    Personally, I'd use a Highlight Box to accomplish this. But that's just me.
    Here are the steps for a square drawing object. I'll assume you have already inserted the object and placed it and all you want are instructions for dealing with the fill.
    Look inside the properties inspector at the Fill & Stroke section. Click the Fill color and configure Alpha to 0%.
    Cheers... Rick
    Helpful and Handy Links
    Begin learning Captivate 5 moments from now! $29.95
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcererStone Blog
    Captivate eBooks

  • Need some help with the String method

    Hello,
    I have been running a program for months now that I wrote that splits strings and evaluates the resulting split. I have a field only object (OrderDetail) that the values in the resulting array of strings from the split holds.Today, I was getting an array out of bounds exception on a split. I have not changed the code and from I can tell the structure of the message has not changed. The string is comma delimited. When I count the commas there are 26, which is expected, however, the split is not coming up with the same number.
    Here is the code I used and the counter I created to count the commas:
    public OrderDetail stringParse(String ord)
    OrderDetail returnOD = new OrderDetail();
    int commas = 0;
      for( int i=0; i < ord.length(); i++ )
        if(ord.charAt(i) == ',')
            commas++;
      String[] ordSplit = ord.split(",");
      System.out.println("delims: " + ordSplit.length + "  commas: " + commas + "  "+ ordSplit[0] + "  " + ordSplit[1] + "  " + ordSplit[2] + "  " + ordSplit[5]);
    The rest of the method just assigns values to fields OrderDetail returnOD.
    Here is the offending string (XXX's replace characters to hide private info)
    1096200000000242505,1079300000007578558,,,2013.10.01T23:58:49.515,,USD/JPY,Maker,XXX.XX,XXX.XXXXX,XXXXXXXXXXXXXXXX,USD,Sell,FillOrKill,400000.00,Request,,,97.7190000,,,,,1096200000000242505,,,
    For this particular string, ordSplit.length = 24 and commas = 26.
    Any help is appreciated. Thank you.

    Today, I was getting an array out of bounds exception on a split
    I don't see how that could happen with the 'split' method since it creates its own array.
    For this particular string, ordSplit.length = 24 and commas = 26.
    PERFECT! That is exactly what it should be!
    Look closely at the end of the sample string you posted and you will see that it has trailing empty strings at the end: '1096200000000242505,,,'
    Then if you read the Javadocs for the 'split' method you will find that those will NOT be included in the resulting array:
    http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String)
    split
    public String[] split(String regex)
    Splits this string around matches of the given regular expression.  This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
    Just a hunch but your 'out of bounds exception' is likely due to your code assuming that there will be 26 entries in the array and there are really only 24.

  • Need help with attributed string in NSMenuItem

    I'm trying to implement a contextual menu for a view in one of my applications. I want it to be dynamic, based on where you click in the view. It works fine if I don't try to mess with the font size of the menu. If I try to make the menu font smaller, the menu will appear blank, and its action won't get triggered, but only if there's only one menu item. If there are two or more, they'll all show up.
    I've done a bunch of searching, and found some code examples where they put in a dummy item, then remove it later, but so far, that hasn't helped me, either. I've posted an example project (~44KB) on my web site that illustrates this, if you'd like to see it in action (the example doesn't include the "dummy fix", by the way, but it's easy enough to add).
    Here's the code where I customize the menu:
    <pre class="command">-(NSMenu *)menuForEvent:(NSEvent *)theEvent
    NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
    NSLog(@"Raw Mouse Location: %2.1f, %2.1f", mouseLoc.x, mouseLoc.y);
    // Get my blank menu:
    NSMenu *tzMenu = [self defaultMenu];
    // Set up my string attributes:
    NSMutableDictionary *menuAttributes = [[NSMutableDictionary alloc] init];
    [menuAttributes setObject:[NSFont fontWithName:@"Lucida Grande" size:11] forKey:NSFontAttributeName];
    if (mouseLoc.x < 220) // Make just one menu item.
    int i;
    for (i=0; i<1; i++)
    [tzMenu addItemWithTitle:@"Item" action:@selector(changeMapDot:) keyEquivalent:@""];
    NSMenuItem *lastItem = [tzMenu itemAtIndex:[tzMenu numberOfItems] - 1];
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Item" attributes:menuAttributes];
    // Comment out this next line and the menu item appears in the default font:
    [lastItem setAttributedTitle:attrString];
    [attrString release];
    else
    int i;
    for (i=0; i<3; i++) //Make three items. These always appear.
    [tzMenu addItemWithTitle:@"Item" action:@selector(changeMapDot:) keyEquivalent:@""];
    NSMenuItem *lastItem = [tzMenu itemAtIndex:[tzMenu numberOfItems] - 1];
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Item" attributes:menuAttributes];
    [lastItem setAttributedTitle:attrString];
    [attrString release];
    [menuAttributes release];
    return tzMenu;
    }</pre>Any tips that anyone has would be most apprecitated.
    I'm not unalterably opposed to the regular system menu font if there's no way around this (the menus are pretty short: usually less then a dozen items), but aesthetically it looks nicer with a smaller font.
    charlie

    Hi,
    You can use SUBSTR and INSTR
    This should work in Oracle 9:
    WITH     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL <= 3
    ,     got_pos          AS
         SELECT     x.txt
         ,     c.n
         ,     INSTR (x.txt, '[', 1, c.n)     AS l_pos
         ,     INSTR (x.txt, ']', 1, c.n)     AS r_pos
         FROM           table_x  x
         CROSS JOIN    cntr     c
    SELECT        txt
    ,        n
    ,        SUBSTR ( txt
                   , l_pos + 1
                , r_pos - (l_pos + 1)
                   )     AS sub_txt
    FROM        got_pos
    ORDER BY   txt
    ,             n
    ;Sorry, I don't have an Oracle 9 database available now; I had to test this in Oracle 10.
    jimmy437 wrote:
    ... I have tried the "REGEXP_SUBSTR" but my database version is 9i, and it is available only from 10g.That's true. Regular expressions are very useful, but they're not available in Oracle 9 (or earlier).
    Oracle 9 does have an Oracle-supplied package, OWA_PATTERN, that provides some regular expression functionality:
    http://docs.oracle.com/cd/B12037_01/appdev.101/b10802/w_patt.htm
    I know that's the Oracle 10, documentation, but it exists in Oracle 9, too.
    Oracle 9 is very old. You should consider upgrading.

  • Help with unicode String?

    Hi there,
    I have a file that I need to read in and process. Took a while for me to realise it was unicode ("text from my file" was printing out as "t e x t f r o m m y f i l e") - Anyway, got there in teh end using:-
    InputStreamReader fis = InputStreamReader(new FilInputeStream(filename), "UTF16");
    dataSource = new BufferedReader(isr);My problem now is that I'm splitting the line (which is a comma seperated list of numbers) and coverting to int's:-
    String line = dataSource.readLine();
    String[] items = line.split(",");
    int[] values = new int[12];
    for(int i = 1; i < items.length; i++)
       values[i-1] = Integer.parseInt(items);
    Values is what I expect, a list of numbers, but items[] is being set to 0. Is this something to do with unicode? Must admit, I've never given the charater encoding any though up until now.
    Any help would be really appreciated.
    Thank,
    Steve
    using

    Sorry, found it. It was actually a buffer issue. For the record, just because I'm printing output in the middle of the loop, doesn't mean the value exists to be printed by the time System.out.println gets to it (my code was creating an exception for an unrelated reason a few lines down)
    Thanks for your responses.
    Steve

  • Help with sending string using setRequestProperty to servlet

    I have a string that is encrpyted so it uses some wierd characters. An
    example of the integer representation of the characters for a string that is
    not working is:
    26,162,91,52,153,136,227,53,190,0
    When I recieve it on the servlet end and go to use it the integer
    representation of the characters is all messed up therefore I can't decrypt
    it properly. The servlet recieved:
    26,162,91,52, 63 , 63 ,227,53,190,0
    Where did the 63's come form??????? That is a "?" character and was not
    part of the original string. I think it has something to do with when the
    characters are converted to bytes or something but I can't seem to figure
    out a way to fix it so that I get the original characters...
    Please, any help would be very much appreciated. Thanks.

    Hmmm....my last post doesn't appear to make a whole lot of sense. I've got to start getting to bed earlier.
    I guess I was a little excited when I realized what URLEncoder and URLDecoder were doing (by looking at the source, of course) which involves a lot of char conversion on the individual portions of your String. These classes are for US-ASCII text and really don't handle non-printable characters very well.
    The passing of the characters across the connection remains a problem, and (without looking at source code) I believe the same problem is at the root; there is a basic encoding of your String into a format that doesn't support characters that aren't in the code page, and the question marks are substituted.
    I haven't tried, but can suggest, using the encode/decode methods in the javax.mail.internet.MimeUtility class. This class comes with the J2EE download, but I'm afraid it may have some of the same shortcomings when it comes to characters it doesn't like (its methods appear to be mostly for mail HEADERS.)
    You basically need either a UUEncode or Base64 encoder/decoder to translate your String into plaintext before it gets sent to the Servlet. The Java Commerce API (Java Wallet) contains a Base64Encoder/Base64Decoder but it is not licensed for reuse.
    There might be other options (I don't know the full scope of your setup), but if all else fails, I can post a UUEncode class that will convert your encrypted string into plaintext for transmission.

  • Need Help with drawing in Photoshop CC

    I am drawing a picture and want to select and copy an element but don't know how.  Can someone help me please?

    If element is on it's own layer, from Layers panel right click and select duplicate layer.
    Nancy O.

  • Can anyone help with reverse String?

    Hi, Can anyone help me in reversing the string?
    here is Code but it doesn't work well. it just give me the starting word of string.
    public class stringrev {
              //construct String
    private String str;          
    public String reverse (String str) {
    int len =str.length();
              if (len <=1)
              return str;
         String s1= str.substring(0,len-1);     
         return reverse(s1);
    public static void main (String [] args)     {
              stringrev str = new stringrev ();
              String reverse = str.reverse ("jinux 2000");
              System.out.println("Reversed String " +" " + reversed );
    }          

    haven't tested it, but the idea should be ok:
    public String reverseString(String s)
         String t = "";
         for(int i=s.length()-1;i>=0;i--)
              t += s.substring(i,i+1);
         return t;
    }tobias

  • Help with drawing a wedge in postscript?

    I'm using postscript for the first time and need to draw a simple wedge shape.
    I will be using this wedge to translate and rotate and create a hazard symbol.
    how do i draw a wedge?
    thanks

    I'm using postscript for the first time and need to draw a simple wedge shape.
    I will be using this wedge to translate and rotate and create a hazard symbol.
    how do i draw a wedge?
    thanks

Maybe you are looking for

  • Viewing the way of a message through integration process

    Hey, I would like to check the lifecycle of a message through an integration process (IP). Therefore I took the ID of a message that triggers the IP.  Our IP have several sending steps and I would like to see the messages that will be send. In sxmb_m

  • Deployment of WebDynpro Application failed

    I get the following error when I try to deploy by WebDynpro application: Oct 18, 2006 12:05:38 PM /userOut/deploy (com.sap.ide.eclipse.sdm.threading.DeployThreadManager) [Thread[Deploy Thread,5,main]] WARNING: [008]Deployment finished with warning Se

  • Can't activate my iphone on ios 5... Help pls

    I installed ios 5 on my iphone 3gs. Whan i start up iphone i need to choise region, to use location services and more,,,than it need to activate my iphone. But he can't do it becouse now i don'h have service. He says to there is no sim card. And i ca

  • Illustrator 10 on Windows 8.1

    How can I run Illustrator 10 on Windows 8.1?

  • Bevel button and fuzzy type

    I made a button and put a simple bevel filter on it. When I added type to the button the text bleeds into the filter. How can I stop/fix this?