我很困惑 - 在这个刽子手的事情上花了100多个小时
继承人代码:
public class NewJFrame extends javax.swing.JFrame {
protected static final Insets bottomInsets = new Insets(10, 10, 10, 10);
protected static final Insets normalInsets = new Insets(10, 10, 0, 10);
protected static final Insets spacingInsets = new Insets(20, 10, 0, 10);
private int wordGridy;
public static int maximumWrongGuesses =7;
HangmanModel model;
private List<String> word;
private List<JLabel> wordText;
private JPanel outsidePanel;
private JPanel panel;
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
//this.frame = frame
initComponents();
tryingToControl();
}
public void tryingToControl(){
lettersUsedText.setText(model.getNumberOfGuesses());
}
@Override
public void paint(Graphics g)
{
super.paint(g);
Gallows gallows = new Gallows();
Figure figure = new Figure();
Color color1 = Color.BLUE;
Color color2 = Color.BLUE;
g.setColor(color1);
gallows.paintComponent(g);
switch (7) {
case 7:
color2 = Color.red;
figure.drawNoose(g, color2);
case 6:
figure.drawRightLeg(g, color2);
case 5:
figure.drawLeftLeg(g, color2);
case 4:
figure.drawRightArm(g, color2);
case 3:
figure.drawLeftArm(g, color2);
case 2:
figure.drawBody(g, color2);
case 1:
figure.drawHead(g, color2);
}
}
/**
* 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() {
secretWordTitle = new javax.swing.JLabel();
secretWordText = new javax.swing.JLabel();
lettersUsedTitle = new javax.swing.JLabel();
lettersUsedText = new javax.swing.JLabel();
guessTitle = new javax.swing.JLabel();
guessTextField = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
secretWordTitle.setText("Secret Word:");
secretWordText.setText("?????????????");
lettersUsedTitle.setText("Letters Used:");
lettersUsedText.setText(model.getUnguessedLetters());
guessTitle.setText("Enter a guess:");
guessTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
guessTextFieldActionPerformed(evt);
}
});
jButton1.setText("Guess");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Reset Game");
jButton3.setText("Custom Word");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(47, 47, 47)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(guessTitle)
.addComponent(secretWordTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lettersUsedTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(secretWordText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lettersUsedText, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(guessTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton1))))
.addComponent(jButton3)
.addComponent(jButton2))
.addContainerGap(79, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(401, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(secretWordTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(secretWordText, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lettersUsedTitle)
.addComponent(lettersUsedText))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(guessTitle)
.addComponent(guessTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addGap(18, 18, 18)
.addComponent(jButton2)
.addGap(18, 18, 18)
.addComponent(jButton3)
.addGap(30, 30, 30))
);
pack();
}// </editor-fold>
private void guessTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
secretWordText.setText("guess");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField guessTextField;
private javax.swing.JLabel guessTitle;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel lettersUsedText;
private javax.swing.JLabel lettersUsedTitle;
private javax.swing.JLabel secretWordText;
private javax.swing.JLabel secretWordTitle;
// End of variables declaration
}