Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Java Project

  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Java Project

    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/tu...feel/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);
    }
    });
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    What images are you talking about?
    Also, can you use [code][/code] tags when you post multiple line blocks; code tags preserve the format (and don't use that nasty yellow).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •