Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1.  
  2. package pkg2ndyearsem2;
  3.  
  4. import java.awt.event.*;
  5. import java.awt.*;
  6. import javax.swing.*;
  7. import javax.swing.JScrollPane;
  8.  
  9. import static javax.swing.JFrame.EXIT_ON_CLOSE;
  10.  
  11.  
  12. public class Assignment_JOptionPane extends JFrame implements ActionListener {
  13.  
  14. static JFrame f;
  15. static JButton b,b2;
  16. static JTextArea jt;
  17. static JScrollPane sp;
  18. static JOptionPane jo;
  19.  
  20. Assignment_JOptionPane()
  21. {
  22.  
  23. }
  24.  
  25.  
  26. public static void main(String[] args)
  27. {
  28.  
  29. f = new JFrame("Assignment JTextArea");
  30. b = new JButton("Submit");
  31. b2 = new JButton("Reset");
  32. jt = new JTextArea(10, 10);
  33. sp = new JScrollPane(jt);
  34. jo = new JOptionPane();
  35. JPanel p = new JPanel();
  36.  
  37.  
  38.  
  39. Assignment_JOptionPane Pane = new Assignment_JOptionPane();
  40.  
  41. sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  42. sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  43.  
  44. b.addActionListener(Pane);
  45. b2.addActionListener(Pane);
  46.  
  47. p.setLayout(new FlowLayout());
  48. p.add(sp);
  49. p.add(b);
  50. p.add(b2);
  51.  
  52.  
  53.  
  54. f.add(p);
  55. f.setSize(300, 300);
  56. f.setDefaultCloseOperation(EXIT_ON_CLOSE);
  57. f.setVisible(true);
  58. f.setSize(350,300);
  59. f.show();
  60. }
  61.  
  62. public void actionPerformed(ActionEvent e)
  63. {
  64. String s = e.getActionCommand();
  65. if (s.equals("Submit")) {
  66. String text = jt.getText();
  67. jo.showMessageDialog(f,text,"Hello There.",JOptionPane.INFORMATION_MESSAGE);
  68.  
  69. }else if(s.equals("Reset")){
  70. jt.setText(" ");
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement