این نرم افزار را با استفاده از یکی از سمپل های نت بینز ساخته شده که شامل پنج کلاس است!
package com.toy.anagrams.ui;
import com.toy.anagrams.lib.ChemLibrary;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.JFrame;
/**
* Main window of the Chem Game application.
*/
public class Chembazi extends JFrame {
public static void main(String[] args) {
new Chembazi().setVisible(true);
}
private int wordIdx = 0;
private ChemLibrary wordLibrary;
/** Creates new form Anagrams */
public Chembazi() {
wordLibrary = ChemLibrary.getDefault();
initComponents();
getRootPane().setDefaultButton(guessButton);
scrambledWord.setText(wordLibrary.getScrambledWord(wordIdx));
pack();
guessedWord.requestFocusInWindow();
// Center in the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation(new Point((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.width) / 2));
}
/** 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.
*/
//
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
mainPanel = new javax.swing.JPanel();
scrambledLabel = new javax.swing.JLabel();
scrambledWord = new javax.swing.JTextField();
guessLabel = new javax.swing.JLabel();
guessedWord = new javax.swing.JTextField();
feedbackLabel = new javax.swing.JLabel();
buttonsPanel = new javax.swing.JPanel();
guessButton = new javax.swing.JButton();
nextTrial = new javax.swing.JButton();
mainMenu = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
aboutMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
setTitle("شیمی بازی");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
mainPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12));
mainPanel.setMinimumSize(new java.awt.Dimension(297, 200));
mainPanel.setLayout(new java.awt.GridBagLayout());
scrambledLabel.setText("نام ترکیب");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 6);
mainPanel.add(scrambledLabel, gridBagConstraints);
scrambledWord.setColumns(20);
scrambledWord.setEditable(false);
scrambledWord.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
mainPanel.add(scrambledWord, gridBagConstraints);
guessLabel.setDisplayedMnemonic('Y');
guessLabel.setLabelFor(guessedWord);
guessLabel.setText("فرمول ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 6);
mainPanel.add(guessLabel, gridBagConstraints);
guessedWord.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
mainPanel.add(guessedWord, gridBagConstraints);
feedbackLabel.setText(" ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
mainPanel.add(feedbackLabel, gridBagConstraints);
buttonsPanel.setLayout(new java.awt.GridBagLayout());
guessButton.setMnemonic('G');
guessButton.setText("حدس");
guessButton.setToolTipText("Guess the scrambled word.");
guessButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
guessedWordActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
buttonsPanel.add(guessButton, gridBagConstraints);
nextTrial.setMnemonic('N');
nextTrial.setText("ترکیب جدید");
nextTrial.setToolTipText("Fetch a new word.");
nextTrial.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextTrialActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weighty = 1.0;
buttonsPanel.add(nextTrial, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1.0;
mainPanel.add(buttonsPanel, gridBagConstraints);
getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);
mainMenu.setFont(new java.awt.Font("AlArabiya", 0, 13)); // NOI18N
fileMenu.setMnemonic('F');
fileMenu.setText("فایل");
aboutMenuItem.setMnemonic('A');
aboutMenuItem.setText("درباره");
aboutMenuItem.setToolTipText("About");
aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuItemActionPerformed(evt);
}
});
fileMenu.add(aboutMenuItem);
exitMenuItem.setMnemonic('E');
exitMenuItem.setText("خروج");
exitMenuItem.setToolTipText("Quit Team, Quit!");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
fileMenu.add(exitMenuItem);
mainMenu.add(fileMenu);
setJMenuBar(mainMenu);
}//
private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
new About(this).setVisible(true);
}
private void nextTrialActionPerformed(java.awt.event.ActionEvent evt) {
wordIdx = (wordIdx + 1) % wordLibrary.getSize();
feedbackLabel.setText(" ");
scrambledWord.setText(wordLibrary.getScrambledWord(wordIdx));
guessedWord.setText("");
getRootPane().setDefaultButton(guessButton);
guessedWord.requestFocusInWindow();
}
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void guessedWordActionPerformed(java.awt.event.ActionEvent evt) {
if (wordLibrary.isCorrect(wordIdx, guessedWord.getText())){
feedbackLabel.setText("درست است، بعدی!");
getRootPane().setDefaultButton(nextTrial);
} else {
feedbackLabel.setText("غلط! دوباره سعی کن!");
guessedWord.setText("");
}
guessedWord.requestFocusInWindow();
}
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
// Variables declaration - do not modify
private javax.swing.JMenuItem aboutMenuItem;
private javax.swing.JPanel buttonsPanel;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JLabel feedbackLabel;
private javax.swing.JMenu fileMenu;
private javax.swing.JButton guessButton;
private javax.swing.JLabel guessLabel;
private javax.swing.JTextField guessedWord;
private javax.swing.JMenuBar mainMenu;
private javax.swing.JPanel mainPanel;
private javax.swing.JButton nextTrial;
private javax.swing.JLabel scrambledLabel;
private javax.swing.JTextField scrambledWord;
// End of variables declaration
}
import com.toy.anagrams.lib.ChemLibrary;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.JFrame;
/**
* Main window of the Chem Game application.
*/
public class Chembazi extends JFrame {
public static void main(String[] args) {
new Chembazi().setVisible(true);
}
private int wordIdx = 0;
private ChemLibrary wordLibrary;
/** Creates new form Anagrams */
public Chembazi() {
wordLibrary = ChemLibrary.getDefault();
initComponents();
getRootPane().setDefaultButton(guessButton);
scrambledWord.setText(wordLibrary.getScrambledWord(wordIdx));
pack();
guessedWord.requestFocusInWindow();
// Center in the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation(new Point((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.width) / 2));
}
/** 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.
*/
//
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
mainPanel = new javax.swing.JPanel();
scrambledLabel = new javax.swing.JLabel();
scrambledWord = new javax.swing.JTextField();
guessLabel = new javax.swing.JLabel();
guessedWord = new javax.swing.JTextField();
feedbackLabel = new javax.swing.JLabel();
buttonsPanel = new javax.swing.JPanel();
guessButton = new javax.swing.JButton();
nextTrial = new javax.swing.JButton();
mainMenu = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
aboutMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
setTitle("شیمی بازی");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
mainPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12));
mainPanel.setMinimumSize(new java.awt.Dimension(297, 200));
mainPanel.setLayout(new java.awt.GridBagLayout());
scrambledLabel.setText("نام ترکیب");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 6);
mainPanel.add(scrambledLabel, gridBagConstraints);
scrambledWord.setColumns(20);
scrambledWord.setEditable(false);
scrambledWord.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
mainPanel.add(scrambledWord, gridBagConstraints);
guessLabel.setDisplayedMnemonic('Y');
guessLabel.setLabelFor(guessedWord);
guessLabel.setText("فرمول ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 6);
mainPanel.add(guessLabel, gridBagConstraints);
guessedWord.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
mainPanel.add(guessedWord, gridBagConstraints);
feedbackLabel.setText(" ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
mainPanel.add(feedbackLabel, gridBagConstraints);
buttonsPanel.setLayout(new java.awt.GridBagLayout());
guessButton.setMnemonic('G');
guessButton.setText("حدس");
guessButton.setToolTipText("Guess the scrambled word.");
guessButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
guessedWordActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
buttonsPanel.add(guessButton, gridBagConstraints);
nextTrial.setMnemonic('N');
nextTrial.setText("ترکیب جدید");
nextTrial.setToolTipText("Fetch a new word.");
nextTrial.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextTrialActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weighty = 1.0;
buttonsPanel.add(nextTrial, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1.0;
mainPanel.add(buttonsPanel, gridBagConstraints);
getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);
mainMenu.setFont(new java.awt.Font("AlArabiya", 0, 13)); // NOI18N
fileMenu.setMnemonic('F');
fileMenu.setText("فایل");
aboutMenuItem.setMnemonic('A');
aboutMenuItem.setText("درباره");
aboutMenuItem.setToolTipText("About");
aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuItemActionPerformed(evt);
}
});
fileMenu.add(aboutMenuItem);
exitMenuItem.setMnemonic('E');
exitMenuItem.setText("خروج");
exitMenuItem.setToolTipText("Quit Team, Quit!");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
fileMenu.add(exitMenuItem);
mainMenu.add(fileMenu);
setJMenuBar(mainMenu);
}//
private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
new About(this).setVisible(true);
}
private void nextTrialActionPerformed(java.awt.event.ActionEvent evt) {
wordIdx = (wordIdx + 1) % wordLibrary.getSize();
feedbackLabel.setText(" ");
scrambledWord.setText(wordLibrary.getScrambledWord(wordIdx));
guessedWord.setText("");
getRootPane().setDefaultButton(guessButton);
guessedWord.requestFocusInWindow();
}
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void guessedWordActionPerformed(java.awt.event.ActionEvent evt) {
if (wordLibrary.isCorrect(wordIdx, guessedWord.getText())){
feedbackLabel.setText("درست است، بعدی!");
getRootPane().setDefaultButton(nextTrial);
} else {
feedbackLabel.setText("غلط! دوباره سعی کن!");
guessedWord.setText("");
}
guessedWord.requestFocusInWindow();
}
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
// Variables declaration - do not modify
private javax.swing.JMenuItem aboutMenuItem;
private javax.swing.JPanel buttonsPanel;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JLabel feedbackLabel;
private javax.swing.JMenu fileMenu;
private javax.swing.JButton guessButton;
private javax.swing.JLabel guessLabel;
private javax.swing.JTextField guessedWord;
private javax.swing.JMenuBar mainMenu;
private javax.swing.JPanel mainPanel;
private javax.swing.JButton nextTrial;
private javax.swing.JLabel scrambledLabel;
private javax.swing.JTextField scrambledWord;
// End of variables declaration
}
هیچ نظری موجود نیست:
ارسال یک نظر