I have a little problem what I am trying to do is enter the X coordinates into one jTextField and Y coordinate into another jTextfield and when I press GO! jButton it displays it on the jPanel, and then next depending on the location and those two points need to be joined bu a line; for jPanel we can assume it is 250 by 200.
I know how to do GUI and the code is bellow but not this stuff any help would be greatly appreciated.
/****************************************************************/
/* XY */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Summary description for XY
*
*/
public class XY extends JFrame
{
// Variables declaration
private JLabel jLabel1;
private JLabel jLabel2;
private JTextField jTextField1;
private JTextField jTextField2;
private JButton jButton1;
private JPanel contentPane;
//-----
private JPanel jPanel1;
//-----
// End of variables declaration
public XY()
{
super();
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jTextField1 = new JTextField();
jTextField2 = new JTextField();
jButton1 = new JButton();
contentPane = (JPanel)this.getContentPane();
//-----
jPanel1 = new JPanel();
//-----
//
// jLabel1
//
jLabel1.setText("X Coordinate");
//
// jLabel2
//
jLabel2.setText("Y Coordinate");
//
// jTextField1
//
jTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField1_actionPerformed(e);
}
});
//
// jTextField2
//
jTextField2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField2_actionPerformed(e);
}
});
//
// jButton1
//
jButton1.setText("GO!");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
jButton1.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e)
{
jButton1_mousePressed(e);
}
public void mouseReleased(MouseEvent e)
{
jButton1_mouseReleased(e);
}
});
//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jLabel1, 292,251,82,18);
addComponent(contentPane, jLabel2, 292,295,84,17);
addComponent(contentPane, jTextField1, 355,250,57,22);
addComponent(contentPane, jTextField2, 355,292,57,22);
addComponent(contentPane, jButton1, 330,332,62,28);
addComponent(contentPane, jPanel1, 16,23,266,210);
//
// jPanel1
//
jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
//
// XY
//
this.setTitle("XY - extends JFrame");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(700, 500));
}
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jTextField1_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void jTextField2_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField2_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void jButton1_actionPerformed(ActionEvent e)
{
System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void jButton1_mousePressed(MouseEvent e)
{
System.out.println("\njButton1_mousePressed(MouseEvent e) called.");
// TODO: Add any handling code here
}
private void jButton1_mouseReleased(MouseEvent e)
{
System.out.println("\njButton1_mouseReleased(MouseEvent e) called.");
// TODO: Add any handling code here
}
//
// TODO: Add any method code to meet your needs in the following area
//
//============================= Testing ================================//
//= =//
//= The following main method is just for testing this class you built.=//
//= After testing,you may simply delete it. =//
//======================================================================//
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new XY();
}
//= End of Testing =
}