Results 1 to 4 of 4
Thread: How to rewrite this as applet?
- 12-31-2009, 11:37 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
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();
}
});
}
}
- 12-31-2009, 12:31 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What have you done so far? Did you go through Sun's Applets tutorial to find out what applets look like?
-
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.
- 01-01-2010, 06:19 PM #4
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Pass parameter from one applet to another applet in different webpages...
By anubhavranjan in forum Java AppletsReplies: 2Last Post: 09-29-2009, 03:33 PM -
[SOLVED] url rewrite
By mtyoung in forum Java ServletReplies: 3Last Post: 02-02-2009, 10:12 AM -
Rewrite as a function so it can call from main.
By thangli in forum New To JavaReplies: 2Last Post: 11-30-2008, 06:26 AM -
rewrite mousedown code
By brahms666 in forum New To JavaReplies: 0Last Post: 11-26-2008, 01:15 AM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks