how to change the coordinates of JTextfield

i want to change the coordinates of the jtextfield[ ] ...here is the code

import java.awt.*;

import java.applet.*;

import java.util.*;

import java.lang.Math.*;

import javax.swing.*;

import java.awt.Toolkit;

import java.awt.BorderLayout;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class tm extends JApplet implements ActionListener{

public void init()

{

Container contentPane = getContentPane();

contentPane.setLayout(new FlowLayout());

JButton loadi = new JButton("LOAD INPUT STRING");

contentPane.add(loadi);

loadi.addActionListener(this);

JButton loadp = new JButton("LOAD PROGRAM");

contentPane.add(loadp);

loadp.addActionListener(this);

JButton run = new JButton("RUN");

contentPane.add(run);

run.addActionListener(this);

JButton step = new JButton("STEP");

contentPane.add(step);

step.addActionListener(this);

JTextField[] prog = new JTextField[10];

for(int i=0;i<prog.length;i++)

{

prog= new JTextField(10);

contentPane.add(prog);

}

}

public void actionPerformed(ActionEvent e)

{

}

}>

[1277 byte] By [ping.sumita] at [2007-11-26 14:53:36]
# 1
I am new to Java but if you use NetBeans if comes with a gui interface that you can drag and drop on a form.might not be the best way but it is the only why i know how to do itCtop
ctopkellya at 2007-7-8 8:41:57 > top of Java-index,Java Essentials,New To Java...
# 2

first, you have to set the content pane's layout to null.

contentPane.setLayout(null);

Then, with every component you add to the content pane, you have to call setBounds() on. The arguments are:

setBounds(x, y, width, height)

Use this method to set the boundaries of a component. If you just want to change the position, use

setLocation(x, y)

Lord_Jirachia at 2007-7-8 8:41:57 > top of Java-index,Java Essentials,New To Java...
# 3
thanks
ping.sumita at 2007-7-8 8:41:57 > top of Java-index,Java Essentials,New To Java...
# 4
Can I have those dukes now?
Lord_Jirachia at 2007-7-8 8:41:57 > top of Java-index,Java Essentials,New To Java...
# 5

First, when posting code, use the code tags (button above posting box). This will avoid the [ i ] changing your code into illegible italics.

Second, Swing questions should be posted in the Swing forum.

Third, using a null layout is probably not what you want. You didn't say what arrangement you really want the textfields to be in, but using a LayoutManager is most likely better than using a null layout. You can nest as many panels as you want. Maybe put the four buttons on one JPanel inside the content pane, and put the ten textfields on a separate JPanel inside the content pane.

This line is useless:

import java.lang.Math.*;

java.lang.Math is not a package.

And, you never have to import anything in the java.lang package--all classes in that package are imported implicitly.

Your classname "tm" should start with a capital letter, according to standard Java naming conventions. So, "Tm", or something more descriptive (I don't know what "Tm" means, so I can't suggest anything specific myself).

Also, you have the following:

import java.awt.*;

import java.awt.Toolkit;

import java.awt.BorderLayout;

Although it is legal to have both the "*" and specific classes in the same package, in your case, it isn't very useful. You probably should delete the java.awt.* and just import individual classes. You aren't even using the two you imported individually, anyway.

doremifasollatidoa at 2007-7-8 8:41:57 > top of Java-index,Java Essentials,New To Java...
# 6
how can i give you duke points.....tell me the procedure....i am new to this forum...
ping.sumita at 2007-7-8 8:41:57 > top of Java-index,Java Essentials,New To Java...
# 7

somewhere in the screen says award duke dollars with a duke image at a side.

I use normally the XYLayout from jBuilder that alows you to place your components in X-Y coordinates I think its easier this way.

I use the jBuilder but I think other programs have something like it to.

import com.borland.jbcl.layout.XYLayout;

import com.borland.jbcl.layout.*;

XYLayout xYLayout1 = new XYLayout();

this.getContentPane().setLayout(xYLayout1);

AnaFrancoa at 2007-7-8 8:41:57 > top of Java-index,Java Essentials,New To Java...
# 8

> I use normally the XYLayout from jBuilder that alows

> you to place your components in X-Y coordinates I

> think its easier this way.

>

> I use the jBuilder but I think other programs have something like it to.

XYLayout is the same as "null" layout, I was told. If you want your Java programs to be portable to other computers and operating systems without a dependence on JBuilder, you shouldn't use XYLayout in the final program.

doremifasollatidoa at 2007-7-8 8:41:57 > top of Java-index,Java Essentials,New To Java...