All pastes #1255805 Raw Edit

InsulterInterface class

public java v1 · immutable
#1255805 ·published 2008-11-14 02:35 UTC
rendered paste body
import java.util.*;/* * InsulterInterface.java * * Created on October 28, 2008, 7:37 PM *//** * * @author  Jake Gunter */public class InsulterInterface extends javax.swing.JFrame implements Runnable {    private int lastIndex;    private boolean isRunning;    private boolean stopRunning;        /** Creates new form InsulterInterface */    public InsulterInterface() {        this.lastIndex = 200;        this.isRunning = false;        this.stopRunning = false;        initComponents();    }    public void run() {        while (!this.stopRunning) {            insult.setText(this.getRandomInsult());            try {                Thread.sleep(1000);            }            catch(InterruptedException e) {}        }    }    public String getRandomInsult() {        ArrayList<String> insults = new ArrayList<String>(0);        insults.add("Michael is an imbecile.");        insults.add("Michael should go eat a cake!");        insults.add("Michael is a worthless human being.");        insults.add("Michael has no brain.");        insults.add("Michael has no heart.");        insults.add("Michael has no kidneys.");        insults.add("Michael is not even a human.");        insults.add("Michael steals candy from babies.");        insults.add("Michael is immature.");        insults.add("Michael falis at everything he tries.");        insults.add("Michael knows nothing about programming.");        int r;        do            r = (int)Math.round(Math.random() * insults.size() - 1);        while(r == this.lastIndex);        if (r < 0) r = 0;        this.lastIndex = r;        return insults.get(r);    }    /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    @SuppressWarnings("unchecked")    // <editor-fold defaultstate="collapsed" desc="Generated Code">                              private void initComponents() {        insultButton = new javax.swing.JButton();        exitButton = new javax.swing.JButton();        jScrollPane1 = new javax.swing.JScrollPane();        insult = new javax.swing.JTextArea();        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);        setTitle("Michael Insulter 2.0");        insultButton.setText("Insult Michael!");        insultButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                insultButtonActionPerformed(evt);            }        });        exitButton.setText("Exit");        exitButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                exitButtonActionPerformed(evt);            }        });        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);        insult.setColumns(20);        insult.setEditable(false);        insult.setRows(5);        jScrollPane1.setViewportView(insult);        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addComponent(insultButton)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)                .addComponent(exitButton)                .addContainerGap())            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(insultButton, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(exitButton))                .addContainerGap())        );        pack();    }// </editor-fold>                        private void insultButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                 if (!this.isRunning) {        this.isRunning = true;        insultButton.setText("Stop insulting Michael.");        this.stopRunning = false;        new Thread(this).start();    }    else if (this.isRunning) {        insultButton.setText("Insult Michael!");        insult.setText("");        this.stopRunning = true;        this.isRunning = false;    }}                                            private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               this.setVisible(false);}                                              public void runInsulter() {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new InsulterInterface().setVisible(true);            }        });    }        // Variables declaration - do not modify                         private javax.swing.JButton exitButton;    private javax.swing.JTextArea insult;    private javax.swing.JButton insultButton;    private javax.swing.JScrollPane jScrollPane1;    // End of variables declaration                       }