View Single Post
  #10 (permalink)  
Old 10-07-2008, 01:08 AM
serjant's Avatar
serjant serjant is offline
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 356
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
here is you program 3,but it is JFrame,you should read about how to make Applets and change some code

Code:
import javax.swing.*; import java.awt.event.*; public class Frame extends JFrame{ private JButton addText=new JButton("Add text"); private JTextArea textArea=new JTextArea(); private JTextField textField=new JTextField(""); public Frame(String name){ super(name); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.getContentPane().add(this.addComponents()); this.setSize(200,300); this.setVisible(true); } private JPanel addComponents(){ JPanel p=new JPanel(); p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS)); p.add(textField); p.add(addText); p.add(textArea); addText.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ textArea.append(textField.getText()+"\n"); textField.setText(""); } }); return p; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new Frame("My prog"); } }
Reply With Quote