package java_jui;
//we should import jframe class
import javax.swing.*;//all class of swing imported
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Java_JUI {
public static void main(String[] args) {
JFrame f=new JFrame();
//textarea
JTextArea area=new JTextArea();
area.setBounds(20,30,250, 200);
area.setBackground(Color.gray);
area.setForeground(Color.WHITE);
//now how to get textarea text
//jbutton
JButton btn=new JButton();
btn.setBounds(280,40,100, 30);
btn.setText("click");
JTextField txt=new JTextField();
txt.setBounds(280,80, 100, 30);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//JOptionPane.showMessageDialog(f,area.getText());
//or
//txt.setText(area.getText());
//area.setText(txt.getText());
area.append(txt.getText()+"\n");
}
});
f.add(txt);
f.add(btn);
f.add(area);
f.setSize(400, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setLayout(null);
f.setVisible(true);
}
}