Results 1 to 10 of 10
  1. #1
    thamizhsmith is offline Member
    Join Date
    Aug 2012
    Location
    puducherry
    Posts
    5
    Rep Power
    0

    Question How to add a new empty line in an applet?

    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...!

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: How to add a new empty line in an applet?

    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.

  4. #4
    thamizhsmith is offline Member
    Join Date
    Aug 2012
    Location
    puducherry
    Posts
    5
    Rep Power
    0

    Default Re: How to add a new empty line in an applet?

    Thank you mine0926 and wsaryada. i will try it out on my program

  5. #5
    thamizhsmith is offline Member
    Join Date
    Aug 2012
    Location
    puducherry
    Posts
    5
    Rep Power
    0

    Default Re: How to add a new empty line in an applet?

    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?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,320
    Rep Power
    25

    Default Re: How to add a new empty line in an applet?

    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.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    thamizhsmith is offline Member
    Join Date
    Aug 2012
    Location
    puducherry
    Posts
    5
    Rep Power
    0

    Default Re: How to add a new empty line in an applet?

    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...?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,320
    Rep Power
    25

    Default Re: How to add a new empty line in an applet?

    it's not working
    Can you post the code that is 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.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    thamizhsmith is offline Member
    Join Date
    Aug 2012
    Location
    puducherry
    Posts
    5
    Rep Power
    0

    Default Re: How to add a new empty line in an applet?

    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;
    }
    }

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: How to add a new empty line in an applet?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 5
    Last Post: 10-14-2011, 11:16 PM
  2. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  3. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  4. Replies: 4
    Last Post: 09-10-2009, 10:18 AM
  5. Applet with scrolling status line
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-10-2008, 02:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •