Guest User

Untitled

a guest
Jun 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4.  
  5. @SuppressWarnings("serial")
  6. public class Schiff extends Frame implements ActionListener, WindowListener {
  7.  
  8. Button b1;
  9. Button b2;
  10. Button b3;
  11. Button b4;
  12. Label l1;
  13. Label l2;
  14. TextField t1;
  15.  
  16. public Schiff() {
  17.  
  18. this.setLayout( new GridLayout( 3, 3 ) );
  19. this.addWindowListener( this );
  20.  
  21. b1 = new Button( "Hallo Welt" );
  22. b2 = new Button( "Wie geht es dir" );
  23. b3 = new Button( "mir ist langweilig" );
  24. b4 = new Button( "Aendere Aufschrift" );
  25. l1 = new Label( "Horst hans Peter" );
  26. l2 = new Label( "Juergen Hans Detlef" );
  27. t1 = new TextField( 10 );
  28.  
  29. this.add( b1 );
  30. this.add( b2 );
  31. this.add( b3 );
  32. this.add( b4 );
  33. this.add( l1 );
  34. this.add( l2 );
  35. this.add( t1 );
  36.  
  37. b1.addActionListener( this );
  38. b2.addActionListener( this );
  39. b3.addActionListener( this );
  40. b4.addActionListener( this );
  41.  
  42. this.setSize( 650, 400 );
  43. //this.setLayout( new FlowLayout() );
  44. this.setVisible( true );
  45.  
  46. }
  47.  
  48. public void aendereAufschrift( String s ) {
  49.  
  50. b1.setLabel( s );
  51. b2.setLabel( s );
  52. b3.setLabel( s );
  53. l1.setText( s );
  54. l2.setText( s );
  55.  
  56. }
  57.  
  58. public void actionPerformed(ActionEvent e) {
  59. if( e.getSource() == b1 ) {
  60.  
  61. b1.setVisible( false );
  62.  
  63. }
  64.  
  65. if( e.getSource() == b2 ) {
  66.  
  67. b2.setVisible( false );
  68.  
  69. }
  70.  
  71. if( e.getSource() == b3 ) {
  72.  
  73. b3.setVisible( false );
  74. System.exit( 0 );
  75.  
  76. }
  77.  
  78. if( e.getSource() == b4 ) {
  79.  
  80. this.aendereAufschrift( t1.getText() );
  81.  
  82. }
  83.  
  84.  
  85. }
  86.  
  87. public void windowActivated(WindowEvent e) {
  88. }
  89. public void windowClosed(WindowEvent e) {
  90.  
  91. System.exit( 0 );
  92.  
  93. }
  94. public void windowClosing(WindowEvent e) {
  95.  
  96. System.exit( 0 );
  97.  
  98. }
  99. public void windowDeactivated(WindowEvent e) {
  100. }
  101. public void windowDeiconified(WindowEvent e) {
  102. }
  103. public void windowIconified(WindowEvent e) {
  104. }
  105. public void windowOpened(WindowEvent e) {
  106. }
  107.  
  108. }
Add Comment
Please, Sign In to add comment