Hi i'm new to java. I have created 3 text boxes along with their labels in an applet. The text boxes are being placed in a single line. How can i add them one after another in a new line?
Give any Hunches or answers please...!
Printable View
Hi i'm new to java. I have created 3 text boxes along with their labels in an applet. The text boxes are being placed in a single line. How can i add them one after another in a new line?
Give any Hunches or answers please...!
Yes, you need to use the correct layout manager for your applet. In your case it will defaulted to use the FlowLayout layout manager. So your component will be rendered from left to right, top to bottom of your frame by default.
Thank you mine0926 and wsaryada. i will try it out on my program
And one more question i have a main applet window which contains all of my text box, radio buttons, buttons etc. when i click on a button submit it have to open the frame window and the frame window should contain all of the details in the first window.
i done that the frame window was opening but i can print any of my information over there.? can you please help me?
Add some component to the frame that will display the information in the format that you want to see it.
A simple component would be a textfield.
Norm i tried with a TextArea so that i can while clicking on the button i can pass the important information from the applet window to another frame window. but it's not working. can you illustrate me with an example so that you can communicate from one applet window to another frame window...?
Can you post the code that is not working?Quote:
it's not working
To call a method of a class object( textarea) defined in another class (frame) you need a reference to the class so you can call its methods.
This was the code which was sent by SRaith to me it's working perfectly with a label. now i'm trying it with a text-box.
package Application;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Application extends Applet implements ItemListener, ActionListener {
String msg = "", item, info, gen;
TextField name1, dob;
Button submit;
Label name, dOB, gender, enclosure;
Checkbox male, female, sslc, hsc, degree, diploma;
CheckboxGroup genderGroup;
public void init() {
name = new Label( "Name" );
dOB = new Label( "Date of Birth" );
gender = new Label( "Gender" );
enclosure = new Label( "Encloused with" );
name1 = new TextField( 20 );
dob = new TextField( 10 );
genderGroup = new CheckboxGroup();
submit = new Button( "Submit" );
male = new Checkbox( "Male", genderGroup, false );
female = new Checkbox( "Female", genderGroup, false );
sslc = new Checkbox( "SSLC" );
hsc = new Checkbox( "HSC" );
diploma = new Checkbox( "Diploma" );
degree = new Checkbox( "Degree" );
add( name );
add( name1 );
add( dOB );
add( dob );
add( gender );
add( male );
add( female );
add( enclosure );
add( sslc );
add( hsc );
add( diploma );
add( degree );
add( submit );
submit.addActionListener( this );
male.addItemListener( this );
female.addItemListener( this );
sslc.addItemListener( this );
hsc.addItemListener( this );
diploma.addItemListener( this );
degree.addItemListener( this );
}
private class Result extends JFrame {
public Result() {
setTitle( "The Application Details" );
setSize( 300, 200 );
setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
setLocationRelativeTo( null );
JPanel mainPanel = new JPanel( null );
JLabel nameLabel = new JLabel( "Name:" );
nameLabel.setBounds( 10, 10, 50, 20 );
mainPanel.add( nameLabel );
JLabel name = new JLabel( getNameFromTextField() );
name.setBounds( 120, 10, 100, 20 );
mainPanel.add( name );
JLabel dobLabel=new JLabel("Date of Birth");
dobLabel.setBounds(10,22,50,20);
mainPanel.add(dobLabel);
JLabel dob=new JLabel(getDateOfBirth());
dob.setBounds(120,22,100,20);
mainPanel.add(dob);
JLabel genderLabel = new JLabel( "Gender:" );
genderLabel.setBounds( 10, 35, 50, 20 );
mainPanel.add( genderLabel );
JLabel gender = new JLabel( getGenderFromGroup() );
gender.setBounds( 120, 35, 50, 20 );
mainPanel.add( gender );
JLabel enclousedWithLabel = new JLabel( "Encloused with:" );
enclousedWithLabel.setBounds( 10, 60, 100, 20 );
mainPanel.add( enclousedWithLabel );
JLabel enclousedWith = new JLabel( getEnclousedWith() );
enclousedWith.setBounds( 120, 60, 150, 20 );
mainPanel.add( enclousedWith );
add( mainPanel );
setVisible( true );
}
}
public void itemStateChanged( ItemEvent ie ) {
msg = "You have selected the radio button";
repaint();
}
public void actionPerformed( ActionEvent ae ) {
String str;
str = ae.getActionCommand();
info = name1.getText();
msg = "You have Pressed Submit Button";
if( ae.getActionCommand().equals( "Submit" ) ) {
new Result();
}
}
public void paint( Graphics g ) {
g.drawString( msg, 100, 100 );
}
public String getNameFromTextField() {
if( name1.getText() == null ) {
return "";
}
return name1.getText();
}
public String getDateOfBirth(){
return dob.getText();
}
public String getGenderFromGroup() {
if( genderGroup.getSelectedCheckbox() == null ) {
return "Male";
}
return genderGroup.getSelectedCheckbox().getLabel();
}
public String getEnclousedWith() {
String enclousedWith = "";
if( sslc.getState() ){
enclousedWith += "sslc ";
}
if( hsc.getState() ) {
enclousedWith += "hsc ";
}
if( degree.getState() ) {
enclousedWith += "degree ";
}
if( diploma.getState() ) {
enclousedWith += "diploma ";
}
return enclousedWith;
}
}