Demo entry 6317782

hw

   

Submitted by anonymous on Nov 06, 2016 at 06:51
Language: Java. Code size: 2.5 kB.

/*
 * Sample.java
 * Class description and usage here.
 * Modified on 6 November 2016
 */

package internetics;

/**
 * @author  Coderwrong
 * @version 1.3
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

// import com.ralph.*;
 
public class Sample extends JFrame
       implements java.awt.event.ActionListener{

  private JButton jButton1;  // this button is for pressing
  private JLabel jLabel1;
  private String name;
  //private BufferedReader input;
  private Scanner input;

  /** Creates new object ChooseFile */
  public Sample() {
    initComponents();
    name = "";
    selectInput();
  }
  
  public Sample(String name) {
    this();
    this.name = name;
  }
  
  private void initComponents() {
    Color bright = Color.red;
    jButton1 = new JButton();
    jLabel1= new JLabel();

    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent evt) {
        exitForm(evt);
      }
    });
    getContentPane().setLayout(new java.awt.GridLayout(2, 1));
    jButton1.setBackground(Color.white);
    jButton1.setFont(new Font("Verdana", 1, 12));
    jButton1.setForeground(bright);
    jButton1.setText("Click Me!");
    jButton1.addActionListener(this);
    jLabel1.setFont(new Font("Verdana", 1, 18));
    jLabel1.setText("Group 23");
    jLabel1.setOpaque(true);
    getContentPane().add(jButton1);
    getContentPane().add(jLabel1);
    pack();
  };
  
  public void actionPerformed(ActionEvent evt) {
    System.out.print("Talk to me " +name+ " : ");
    try {
      jLabel1.setText(input.nextLine());
    } catch (Exception ioe) {
      jLabel1.setText("Ow! You pushed my button");
      System.err.println("IO Error: " + ioe);
    }
  }
  
  /** Exit this Application */
  private void exitForm(WindowEvent evt) {
    System.exit(0);
  }
  
  /** Initialise and Buffer input Stream */
  private void selectInput() {
    //input = new BufferedReader(new InputStreamReader(System.in));
    input = new Scanner(System.in);
  }
  
  /** Getter for name prompt */
  public String getName() {
    return name;
  }
  
  /** Setter for name prompt */
  public void setName(String name) {
  this.name = name;
  }
  
  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    new Sample("Coderwrong").show();
  }
  
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).