...

View Full Version : Java Project



thepanther
02-08-2012, 02:45 PM
hi all im new to this site just joined, im doing a little game and i need to add the images to my game can anyone help me on this and here is the code

thanks paul...

public class HangMan extends javax.swing.JFrame {

String FindWord = "hello";

public HangMan() {
initComponents();
}

@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();
Char5 = new javax.swing.JLabel();
ALetter = new javax.swing.JTextField();
InCorrect = new javax.swing.JLabel();
MyMessage = new javax.swing.JLabel();
TryLetter = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("HangMan");

Char0.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
Char0.setText("_");

Char1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
Char1.setText("_");

Char2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
Char2.setText("_");

Char3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
Char3.setText("_");

Char4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
Char4.setText("_");

Char5.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
Char5.setText("_");

ALetter.setText("e");

InCorrect.setText("0");

MyMessage.setText("Look Here");

TryLetter.setText("Try Letter");
TryLetter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TryLetterActionPerformed(evt);
}
});

jLabel1.setText("Enter Letter Here");

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.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(TryLetter)
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(MyMessage)
.addComponent(InCorrect, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(161, 161, 161)))
.addGroup(layout.createSequentialGroup()
.addGap(115, 115, 115)
.addComponent(Char0)
.addGap(18, 18, 18)
.addComponent(Char1)
.addGap(18, 18, 18)
.addComponent(Char2)
.addGap(18, 18, 18)
.addComponent(Char3)
.addGap(18, 18, 18)
.addComponent(Char4)
.addGap(18, 18, 18)
.addComponent(Char5))
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(ALetter, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(135, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Char0)
.addComponent(Char1)
.addComponent(Char2)
.addComponent(Char3)
.addComponent(Char4)
.addComponent(Char5))
.addGap(43, 43, 43)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ALetter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(InCorrect)
.addGap(27, 27, 27)
.addComponent(MyMessage)
.addGap(28, 28, 28)
.addComponent(TryLetter)
.addContainerGap(38, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void TryLetterActionPerformed(java.awt.event.ActionEvent evt) {

int charPos = +1;

String letter = ALetter.getText();
charPos = FindWord.indexOf(letter);
MyMessage.setText("Position is " + charPos);

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);


}

public static void main(String args[]) {

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(HangMan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(HangMan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(HangMan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(HangMan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
new HangMan().setVisible(true);
}
});
}

Fou-Lu
02-08-2012, 09:05 PM
What images are you talking about?
Also, can you use
tags when you post multiple line blocks; code tags preserve the format (and don't use that nasty yellow).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum