We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,664 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Center Point GUI

0
By Arman Majumder on Jun 16th, 2007 3:32 am

A very simple program, which displays the coordinate points for the center point of the panel. Automatically updates the (X,Y) form coordinates with size modification.

// Arman Majumder
// Center Point (X,Y) GUI

   import javax.swing.*;
   import java.awt.*;
   import java.awt.event.*;
       
    public class XY extends JPanel
   {
       public XY (Color backColor)
      {
         setBackground(backColor);
      }
      
       public void paintComponent(Graphics g)
      {
         super.paintComponent(g);
         int x = getWidth() / 2 - 60;
         int y = getHeight() / 2;
         g.setColor(Color.red);
         Font font = new Font("Arial", Font.PLAIN, 14);
         g.setFont(font);
         g.drawString("( " + x + ", " + y + " )", x + 10, y + 15);	
      }
   	
       public static void main(String [] args)
      {
         JFrame theGUI = new JFrame();
         theGUI.setTitle("(X,Y)");
         theGUI.setSize(400, 400);
         theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         XY panel = new XY(Color.black);
         Container pane = theGUI.getContentPane();
         pane.add(panel);
         theGUI.setVisible(true);
      }
   }

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0800 seconds using 2.83MB