Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding text from textfield into an image

843805Feb 12 2006 — edited Feb 14 2006
Hi guys,

I'm stuck on a problem which I can't magae to get around.
Basically, my program demonstrates a working stack, where I have managed to show the stack grow everytime the user clicks push. BUT, I want the value they insert into the textfield to come inside the stack layer, which I use as a jpg file. The following code is what I have so far that makes the stack add only the layers, but not the content inside them. How could I solve this problem?

Much appreciated,

(NOTE: button1 is defined before, I'm only showing the action part of it here)
  if(!stack.isFull() && e.getSource() == button1)
	  {
	      String textFieldString = text.getText();
		 			  //String textFieldString = text.getText();
		 			  stack.push(textFieldString);
		 			  message.append("You have just entered "+textFieldString+" into the Stack\n");


                                         if (stack.size() >= 0 ) // keeps drawing to the limit of 10 (set in MainStack)
                                         {


                                         JLabel pic1 = new JLabel();
   		                                 pic1.setIcon(new ImageIcon(getClass().getResource("p1.jpg")));
                                       //pic1.drawString(""+textFieldString);


		                                 Insets insets = displayPanel.getInsets();
		   					             Dimension size = pic1.getPreferredSize();

		   							     pic1.setBounds(90 + insets.left, stackLayer + insets.top,
		   					             size.width, size.height);

		                                 displayPanel.setLayout(null);
		                                 displayPanel.add(pic1);
                                         displayPanel.revalidate();
                                         stackLayer = stackLayer - 30;
									      }

     }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 14 2006
Added on Feb 12 2006
22 comments
570 views