this is my code so far
*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* HangForm.java
* /*.indexOf();
* /*.ShowLetter();
*
* Created on 03-Feb-2011, 12:32:45
*/
/**
*
* @author sam
*/
public class HangForm extends javax.swing.JFrame {
String FindWord = "apple";
/** Creates new form HangForm */
public HangForm() {
initComponents();
}
/** 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() {
Char0 = new javax.swing.JLabel();
Char1 = new javax.swing.JLabel();
Char2 = new javax.swing.JLabel();
Char3 = new javax.swing.JLabel();
Char4 = new javax.swing.JLabel();
ALetter = new javax.swing.JTextField();
inCorrect = new javax.swing.JLabel();
MyMessage = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
Char5 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Hang Man");
Char0.setText("X");
Char1.setText("X");
Char2.setText("X");
Char3.setText("X");
Char4.setText("X");
ALetter.setText("e");
inCorrect.setText("0");
MyMessage.setText("look here");
jButton1.setText("Try Letter");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/s1.jpg.jpg"))); // NOI18N
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/outside.jpg"))); // NOI18N
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/s3.jpg.jpg"))); // NOI18N
jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/s4.jpg.jpg"))); // NOI18N
jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/s5.jpg.jpg"))); // NOI18N
jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/s6.jpg.jpg"))); // NOI18N
jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/s7.jpg.jpg"))); // NOI18N
jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/s9.jpg.jpg"))); // NOI18N
Char5.setText("X");
jButton2.setText("jButton2");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(71, 71, 71)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(ALetter, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(252, 252, 252))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(MyMessage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 155, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(inCorrect)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 193, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(Char0)
.addGap(32, 32, 32)
.addComponent(Char1)
.addGap(29, 29, 29)
.addComponent(Char2)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addGroup(layout.createSequentialGroup()
.addComponent(Char3)
.addGap(37, 37, 37)
.addComponent(Char4)))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Char5)
.addGap(75, 75, 75)))
.addGap(212, 212, 212))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addGap(148, 148, 148)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(116, 116, 116)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel9))))
.addGroup(layout.createSequentialGroup()
.addGap(139, 139, 139)
.addComponent(jLabel7)))
.addGap(1253, 1253, 1253))
.addGroup(layout.createSequentialGroup()
.addGap(318, 318, 318)
.addComponent(jLabel8)
.addContainerGap(1599, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(645, 645, 645)
.addComponent(jButton2)
.addContainerGap(1415, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(169, 169, 169)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Char4)
.addComponent(Char3)
.addComponent(Char2)
.addComponent(Char1)
.addComponent(Char0)
.addComponent(Char5))
.addGap(39, 39, 39)
.addComponent(ALetter, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel9))
.addGap(11, 11, 11)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addGroup(layout.createSequentialGroup()
.addComponent(inCorrect)
.addGap(18, 18, 18)
.addComponent(MyMessage))
.addGroup(layout.createSequentialGroup()
.addGap(11, 11, 11)
.addComponent(jLabel1)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap(311, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(125, 125, 125)
.addComponent(jLabel4)))
.addGap(27, 27, 27)
.addComponent(jLabel6)
.addGap(142, 142, 142)
.addComponent(jLabel8)
.addGap(26, 26, 26)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(189, 189, 189)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addGap(62, 62, 62))
);
Char0.getAccessibleContext().setAccessibleName("Char0");
Char1.getAccessibleContext().setAccessibleName("Char1");
Char2.getAccessibleContext().setAccessibleName("Char0");
Char3.getAccessibleContext().setAccessibleName("Char3");
Char4.getAccessibleContext().setAccessibleName("Char4");
ALetter.getAccessibleContext().setAccessibleName("aLetter");
inCorrect.getAccessibleContext().setAccessibleName("inCorrect");
MyMessage.getAccessibleContext().setAccessibleName("MyMessage");
jButton1.getAccessibleContext().setAccessibleName("tryLetter");
getAccessibleContext().setAccessibleName("");
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
{
int charPos = 1;
String letter = ALetter.getText();
MyMessage.setText("position is " + charPos);
charPos = FindWord.indexOf(letter);
if (charPos == 0)Char0.setText(letter);
if (charPos == 1)Char1.setText(letter);
if (charPos == 2)Char2.setText(letter);
if (charPos == 3)Char3.setText(letter);
if (charPos == 4)Char4.setText(letter);
if (charPos == 5)Char5.setText(letter);
MyMessage.setText("position is " + charPos);
charPos = FindWord.indexOf(letter, charPos+1);
if (charPos == 0)Char0.setText(letter);
if (charPos == 1)Char1.setText(letter);
if (charPos == 2)Char2.setText(letter);
if (charPos == 3)Char3.setText(letter);
if (charPos == 4)Char4.setText(letter);
if (charPos == 5)Char5.setText(letter);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new HangForm().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField ALetter;
private javax.swing.JLabel Char0;
private javax.swing.JLabel Char1;
private javax.swing.JLabel Char2;
private javax.swing.JLabel Char3;
private javax.swing.JLabel Char4;
private javax.swing.JLabel Char5;
private javax.swing.JLabel MyMessage;
private javax.swing.JLabel inCorrect;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
// End of variables declaration
}
This post has been edited by macosxnerd101: 11 February 2011 - 07:05 AM
Reason for edit:: Please use code tags

New Topic/Question
Reply
MultiQuote






|