Results 1 to 4 of 4
  1. #1
    tpname is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default How to rewrite this as applet?

    I would like to rewrite this application as an applet. I need the input (enter text) and output (hundreds of lines in scrolling panel) for an applet to run in a web browser. Does anyone know how to do this?


    package pakke;

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class Applet extends JPanel implements ActionListener {
    protected JTextField textField;
    protected JTextArea textArea;
    private final static String newline = "\n";
    public String utstreng;

    public Applet() {
    super(new GridBagLayout());

    textField = new JTextField(16);
    textField.addActionListener(this);

    textArea = new JTextArea(44, 16);
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Add Components to this panel.
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = GridBagConstraints.REMAINDER;

    c.fill = GridBagConstraints.HORIZONTAL;
    add(textField, c);

    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    add(scrollPane, c);
    }


    public void skriv(String thisText){
    textArea.append(thisText + newline);
    }

    public void actionPerformed(ActionEvent evt) {
    String text = textField.getText();
    utstreng = text;
    skriv(utstreng);
    textField.selectAll();

    //Make sure the new text is visible, even if there
    //was a selection in the text area.
    textArea.setCaretPosition(textArea.getDocument().g etLength());

    }

    /**
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event dispatch thread.
    */
    private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("Vindu");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    //Add contents to the window.
    frame.add(new Applet());

    //Display the window.
    frame.pack();
    frame.setVisible(true);
    }

    public static void main(String[] args) {
    //Schedule a job for the event dispatch thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }
    });
    }
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    What have you done so far? Did you go through Sun's Applets tutorial to find out what applets look like?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    28

    Default

    There's no need to re-write the code above. Simply create a new class that extends JApplet and then add the JPanel created above into your JApplet's contentPane. As r-etc recommends, check out the Sun applet tutorial for more details.

  4. #4
    tpname is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    Solved.

    Google and a tutorial worked fine.

    :-)
    Last edited by tpname; 01-24-2010 at 01:32 PM.

Similar Threads

  1. Replies: 2
    Last Post: 09-29-2009, 03:33 PM
  2. [SOLVED] url rewrite
    By mtyoung in forum Java Servlet
    Replies: 3
    Last Post: 02-02-2009, 11:12 AM
  3. Rewrite as a function so it can call from main.
    By thangli in forum New To Java
    Replies: 2
    Last Post: 11-30-2008, 07:26 AM
  4. rewrite mousedown code
    By brahms666 in forum New To Java
    Replies: 0
    Last Post: 11-26-2008, 02:15 AM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Posting Permissions

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