Results 1 to 4 of 4
- 02-29-2012, 05:48 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
Putting Label Inside Rectangle Problem
Had draw rectangle and there is button with textfield in Frame...So if i write something in textfield and press button it should be displayed in rectangle...But how....i have not pasted all the codes because i want only the way ...So is there any way;? Help Please
-
Re: Putting Label Inside Rectangle Problem
What GUI library? AWT? Swing? What have you tried? Can you show your code (with code tags)? Have you tried putting a border around the label?
- 03-01-2012, 12:55 AM #3
Member
- Join Date
- Feb 2012
- Posts
- 9
- Rep Power
- 0
Re: Putting Label Inside Rectangle Problem
These are the codes..here when i click button the text inside textfield should go inside rectangle
Components Class
Java Code:import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.JComponent; class Components extends JComponent { Rectangle rect = new Rectangle(50,80,100,150); private int x; private int y;* public *Components() { class ClickRect implements MouseListener { public void mouseClicked(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e)* { x=e.getX(); y=e.getY(); } public void mouseReleased(MouseEvent e) {} } MouseListener mln = new ClickRect(); addMouseListener(mln); class MovRect implements MouseMotionListener { public void mouseDragged(MouseEvent event)* { int dx = event.getX()-x; int dy = event.getY()-y; rect.x = rect.x + dx; rect.y= rect.y + dy; repaint(); x+=dx; y+=dy; } public void mouseMoved(MouseEvent event) {} } MouseMotionListener mml = new MovRect(); addMouseMotionListener(mml); } * *public void paintComponent(Graphics g) * *{ * * * Graphics2D g2 = (Graphics2D) g; * * ** * * * g2.draw(rect); * *} }
This is viewer class
Java Code:import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class Viewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(600, 600); frame.setTitle("SuperEllipse Viewer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Components component = new Components(); frame.add(component); JPanel panel = new JPanel(); frame.add(panel,BorderLayout.NORTH); JButton scaleUpButton = new JButton("Click"); panel.add(scaleUpButton); JLabel tatti = new JLabel(""); JLabel bulgeLabel = new JLabel("Click me to put text in rect: "); JTextField txt = new JTextField(20); panel.add(bulgeLabel); panel.add(tatti); panel.add(txt); frame.setVisible(true); } }
Last edited by AryanArs; 03-01-2012 at 01:05 AM.
-
Re: Putting Label Inside Rectangle Problem
Where's the code that's supposed to put the text into the GUI? Where do you add an ActionListener to your JButton? Have you read the ActionListener tutorial? If not you will want to read and study it. If so, you'll probably want to read and study it again, and then make an attempt to solve this.
Similar Threads
-
putting the output of different methods inside a method automatically
By eagle26 in forum New To JavaReplies: 11Last Post: 06-28-2011, 01:47 AM -
need some urgent help for drawing random points inside a rectangle
By pranav21_1983 in forum Java AppletsReplies: 2Last Post: 04-10-2010, 07:35 PM -
centering a label inside a rectangle
By Brain_Child in forum New To JavaReplies: 3Last Post: 11-19-2009, 06:22 PM -
problem in displaying text inside the item label - JFREECHART
By chittora in forum Java 2DReplies: 9Last Post: 07-21-2009, 03:41 AM -
How To Add A Jbutton Inside A Rectangle
By SANDY_INDIA in forum AWT / SwingReplies: 9Last Post: 07-06-2008, 09:06 AM
Bookmarks