Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkg2ndyearsem2;
- import java.awt.event.*;
- import java.awt.*;
- import javax.swing.*;
- import javax.swing.JScrollPane;
- import static javax.swing.JFrame.EXIT_ON_CLOSE;
- public class Assignment_JOptionPane extends JFrame implements ActionListener {
- static JFrame f;
- static JButton b,b2;
- static JTextArea jt;
- static JScrollPane sp;
- static JOptionPane jo;
- Assignment_JOptionPane()
- {
- }
- public static void main(String[] args)
- {
- f = new JFrame("Assignment JTextArea");
- b = new JButton("Submit");
- b2 = new JButton("Reset");
- jt = new JTextArea(10, 10);
- sp = new JScrollPane(jt);
- jo = new JOptionPane();
- JPanel p = new JPanel();
- Assignment_JOptionPane Pane = new Assignment_JOptionPane();
- sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
- b.addActionListener(Pane);
- b2.addActionListener(Pane);
- p.setLayout(new FlowLayout());
- p.add(sp);
- p.add(b);
- p.add(b2);
- f.add(p);
- f.setSize(300, 300);
- f.setDefaultCloseOperation(EXIT_ON_CLOSE);
- f.setVisible(true);
- f.setSize(350,300);
- f.show();
- }
- public void actionPerformed(ActionEvent e)
- {
- String s = e.getActionCommand();
- if (s.equals("Submit")) {
- String text = jt.getText();
- jo.showMessageDialog(f,text,"Hello There.",JOptionPane.INFORMATION_MESSAGE);
- }else if(s.equals("Reset")){
- jt.setText(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement