Results 1 to 3 of 3
  1. #1
    moonclothes is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default append in actionperformed

    This is the code. Why does simply the last textfield string appear in textarea. And what do I do to solve this?

    package kontakt;

    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;

    /**
    *
    * @author 988981
    */
    public class Kontakt extends JFrame implements ActionListener{

    private final static String newline = "\n";

    public Kontakt() {

    //JPanel panel = new JPanel(new FlowLayout());
    setSize(600,400);
    setLayout(new FlowLayout());
    JButton knapp = new JButton("Lagre Resultater");
    final JTextArea area = new JTextArea(20, 30);
    final JTextField navn = new JTextField(10);
    final JTextField tlf = new JTextField(10);
    JButton knappA = new JButton("Arkiver Navn og Tlf");
    JLabel navnA = new JLabel("Navn:");
    JLabel tlfA = new JLabel("Tlf:");
    final String txt = navn.getText();
    final String txtA = tlf.getText();

    //public panel() {
    add(knapp);
    add(area);
    add(navnA);
    add(navn);
    add(tlfA);
    add(tlf);
    add(knappA);
    //}
    knappA.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent ae) {
    area.append(txt + newline);
    area.append(txtA + newline);
    area.setText(navn.getText());
    area.setText(tlf.getText());

    }
    });

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    }
    public static void main(String[] args) {
    new Kontakt();
    //knapp.add.ActionListener(this);


    }

    public void actionPerformed(ActionEvent e) {
    //area.getText(); //navn på to texfield metoder

    //throw new UnsupportedOperationException("Not supported yet.");
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,446
    Rep Power
    18

    Default Re: append in actionperformed

    When posting code please wrap it in [code] tags [/code] otherwise it's difficult to read.

    You might need to try and ask the question again, as I'm not sure what it is that's happening with your code, and what it is that should be happening.
    Please do not ask for code as refusal often offends.

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,074
    Rep Power
    4

    Default Re: append in actionperformed

    I see you manually setting a size. You may want to try and use JFrame.pack() in stead so the window will be nicely fitted around the components.

    Demonstration here:

    http://docs.oracle.com/javase/tutori...nts/frame.html
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. ActionListener - actionPerformed
    By collwill in forum New To Java
    Replies: 2
    Last Post: 04-21-2011, 06:01 PM
  2. Help with actionPerformed
    By mayhewj7 in forum New To Java
    Replies: 8
    Last Post: 02-10-2009, 06:45 PM
  3. trouble with actionPerformed
    By diggitydoggz in forum New To Java
    Replies: 2
    Last Post: 12-26-2008, 02:18 AM
  4. Help with actionPerformed Statements
    By wco5002 in forum New To Java
    Replies: 8
    Last Post: 03-26-2008, 04:02 AM
  5. actionPerformed problem
    By tomitzel in forum New To Java
    Replies: 1
    Last Post: 01-08-2008, 06:10 PM

Tags for this Thread

Posting Permissions

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