جمعه ۲۸ اوت ۲۰۰۹

اضافه کردن لوگو

با اضافه کردن کد زیر در فایل manifest.mf پس از اجرای برنامه چند لحظه عکس nacl که در مسیر
src/images کپی شده است به نمایش در می آید.
SplashScreen-Image: images/nacl.jpg

جمعه ۳ ژوئیهٔ ۲۰۰۹

تبدیل سانتی گراد به فارنهایت

این نرم افزار رو فارسی کرده وتغییرات کوچکی در آن ایجاد شده!

/*
* Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Sun Microsystems nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* CelsiusConverterGUI.java
*
*/

package learn;

import java.awt.event.ActionEvent;

public class CelsiusConverterGUI extends javax.swing.JFrame {

/** Creates new form CelsiusConverterGUI */
public CelsiusConverterGUI() {
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.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
tempTextField = new javax.swing.JTextField();
celsiusLabel = new javax.swing.JLabel();
convertButton = new javax.swing.JButton();
fahrenheitLabel = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("مبدل سانتی گراد");
setLocationRelativeTo(null);
celsiusLabel.setFont(new java.awt.Font("Tahoma", 0, 13));
celsiusLabel.setText("سانتی گراد");

convertButton.setFont(new java.awt.Font("Tahoma", 0, 13));
convertButton.setText("تبدیل");

convertButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
convertButtonActionPerformed(evt);

}
});

tempTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tempTextFieldActionPerformed(evt);

}

private void tempTextFieldActionPerformed(ActionEvent evt) {
int tempFahr = (int)((Double.parseDouble(tempTextField.getText()))
* 1.8 + 32);
fahrenheitLabel.setText(tempFahr + " فارنهایت");
}
});

fahrenheitLabel.setFont(new java.awt.Font("Tahoma", 0, 13));
fahrenheitLabel.setText("فارنهایت");


javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(tempTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(celsiusLabel))
.addGroup(layout.createSequentialGroup()
.addComponent(convertButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fahrenheitLabel)))
.addContainerGap(27, Short.MAX_VALUE))
);

layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {convertButton, tempTextField});

layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tempTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(celsiusLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(convertButton)
.addComponent(fahrenheitLabel))
.addContainerGap(21, Short.MAX_VALUE))
);
pack();
}//
//GEN-END:initComponents

private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed
//Parse degrees Celsius as a double and convert to Fahrenheit
int tempFahr = (int)((Double.parseDouble(tempTextField.getText()))
* 1.8 + 32);
fahrenheitLabel.setText(tempFahr + " فارنهایت");
}//GEN-LAST:event_convertButtonActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CelsiusConverterGUI().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel celsiusLabel;
private javax.swing.JButton convertButton;
private javax.swing.JLabel fahrenheitLabel;
private javax.swing.JTextField tempTextField;
// End of variables declaration//GEN-END:variables

}

0

شنبه ۹ مهٔ ۲۰۰۹

شیمی بازی

این نرم افزار با استفاده از یکی از سمپل های نت بینز نوشته شده که شامل پنج کلاس است!

کلاس اول:

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 Anagram 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

}
۰

کلاس دوم:

package com.toy.anagrams.lib;

/**
* Implementation of the logic for the Anagram Game application.
*/
final class StaticChemLibrary extends ChemLibrary {

private static final String[] FORMULA = {
"Na2SO4",
"K2CO3",
"LiNO3",
"CaCl2",
"Ba3(PO4)2",
"MgF2",
"Al(NO2)3",
"BeCl2",
"ZnCl2",
"SO3",
"SO2",
"CO2",
"CO",
"CCl4",
"NCl3",
"NO",
"NO2",
"N2O3",
"N2O4",
"N2O5",
"Al2(CO3)3",
"PBr3",
"PBr5",
"PbO2",
"KI",
"H2SO4",
"HCl",
"HNO3",
"H3PO4",
"H2CO3",
"H2O2",
"Fe(OH)3",
"NiSO4",
"CS2",
"HNO2",
"H2SO3",
"HClO",
"HClO2",
"HClO3",
"HClO4",
"CuCl",
"CuCl2",
"AgNO3",
"NaHCO3",
"Cr2O3"};

private static final String[] PERSIAN_NAME = {
"سدیم سولفات",
"پتاسیم کربنات",
"لیتیم نیترات",
"کلسیم کلرید",
"باریم فسفات",
"منیزیم فلورید",
"آلومینیم نیتریت",
"برلیم کلرید",
"روی کلرید",
"گوگرد تری اکسید",
"گوگرد دی اکسید",
"کربن دی اکسید",
"کربن منو اکسید",
"کربن تترا کلرید",
"نیتروژن تری کلرید",
"نیتروژن منو اکسید",
"نیتروژن دی اکسید",
"دی نیتروژن تری اکسید",
"دی نیتروژن تترا اکسید",
"دی نیتروژن پنتا اکسید",
"آلومینیم کربنات",
"فسفر تری برمید",
"فسفر پنتا برمید",
"اکسید (IV) سرب",
"پتاسیم یدید",
"سولفوریک اسید",
"هیدرو کلریک اسید",
"نیتریک اسید",
"فسفریک اسید",
"کربنیک اسید",
"هیدروژن پر اکسید",
"هیدرواکسید (III) آهن",
"سولفات (II) نیکل ",
"کربن دی سولفید",
"نیترو اسید",
"سولفورو اسید",
"هیپوکلرو اسید",
"کلرو اسید",
"کلریک اسید",
"پر کلریک اسید",
"کلرید (I) مس",
"کلرید (II) مس",
"نقره نیترات",
"سدیم هیدروژن کربنات",
"اکسید (III) کروم"
};

final static ChemLibrary DEFAULT = new StaticChemLibrary();

/**
* Singleton class.
*/
private StaticChemLibrary() {
}

/**
* Gets the word at a given index.
* @param idx index of required word
* @return word at that index in its natural form
*/
public String getWord(int idx) {
return FORMULA[idx];
}

/**
* Gets the word at a given index in its scrambled form.
* @param idx index of required word
* @return word at that index in its scrambled form
*/
public String getScrambledWord(int idx) {
return PERSIAN_NAME[idx];
}

/**
* Gets the number of words in the library.
* @return the total number of plain/scrambled word pairs in the library
*/
public int getSize() {
return FORMULA.length;
}

/**
* Checks whether a user's guess for a word at the given index is correct.
* @param idx index of the word guessed
* @param userGuess the user's guess for the actual word
* @return true if the guess was correct; false otherwise
*/
public boolean isCorrect(int idx, String userGuess) {
return userGuess.equals(getWord(idx));
}

}
۰

کلاس سوم:



package com.toy.anagrams.lib;

/**
* Interface defining logic for the Anagram Game application.
*/
public abstract class ChemLibrary {
/**
* Constructor for subclasses.
*/
protected ChemLibrary() {
}

/** Getter for the default implementation of the WordLibrary.
* @return some default implementation of WordLibrary
*/
public static ChemLibrary getDefault() {
return StaticChemLibrary.DEFAULT;
}

/**
* Gets the word at a given index.
* @param idx index of required word
* @return word at that index in its natural form
*/
public abstract String getWord(int idx);

/**
* Gets the word at a given index in its scrambled form.
* @param idx index of required word
* @return word at that index in its scrambled form
*/
public abstract String getScrambledWord(int idx);

/**
* Gets the number of words in the library.
* @return the total number of plain/scrambled word pairs in the library
*/
public abstract int getSize();

/**
* Checks whether a user's guess for a word at the given index is correct.
* @param idx index of the word guessed
* @param userGuess the user's guess for the actual word
* @return true if the guess was correct; false otherwise
*/
public abstract boolean isCorrect(int idx, String userGuess);
}
۰

کلاس چهارم:





package com.toy.anagrams.lib;

import java.util.Arrays;
import junit.framework.TestCase;

/**
* Test of the functionality of {@link WordLibrary}.
*/
public class ChemLibraryTest extends TestCase {
ChemLibrary wordLibrary;

public ChemLibraryTest(String testName) {
super(testName);
}

protected void setUp() throws Exception {
wordLibrary = ChemLibrary.getDefault();
}



/**
* Test of {@link WordLibrary#isCorrect}.
*/
public void testIsCorrect() {
for (int i = 0; i < wordLibrary.getSize(); i++) {
String clearWord = wordLibrary.getWord(i);
String scrambledWord = wordLibrary.getScrambledWord(i);
assertTrue("Scrambled word \"" + scrambledWord +
"\" at index: " + i +
" does not represent the word \"" + clearWord + "\"",
isAnagram(clearWord, scrambledWord));
}
}

/**
* Tests whether given anagram represents the word.
* @param clearWord The word in clear text
* @param scrambledWord Scrambled version of the word
* @return true if the scrambledWord is correct anagram of clearWord
*/
private boolean isAnagram(String clearWord, String scrambledWord) {
char[] clearArray = clearWord.toCharArray();
char[] scrambledArray = scrambledWord.toCharArray();
Arrays.sort(clearArray);
Arrays.sort(scrambledArray);
return Arrays.equals(clearArray, scrambledArray);
}

}
۰

کلاس پنجم:


package com.toy.anagrams.ui;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
* About dialog of the Anagram Game application.
*/
public class About extends JDialog {

/** Creates new form About */
public About(JFrame parent) {
super(parent,true);
initComponents();
pack();
Rectangle parentBounds = parent.getBounds();
Dimension size = getSize();
// Center in the parent
int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
setLocation(new Point(x, y));
}

/** 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();
copyrightTextArea = new javax.swing.JTextArea();
closeButton = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("About Anagrams");
getContentPane().setLayout(new java.awt.GridBagLayout());

mainPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(11, 11, 12, 12));
mainPanel.setLayout(new java.awt.GridBagLayout());

copyrightTextArea.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
copyrightTextArea.setColumns(25);
copyrightTextArea.setEditable(false);
copyrightTextArea.setLineWrap(true);
copyrightTextArea.setRows(8);
copyrightTextArea.setText("Created by Kian Kiani\nkiankiani1@yahoo.com\t\n09131005154\n\nSpecial thanks for \nSayesteh Alavi");
copyrightTextArea.setWrapStyleWord(true);
copyrightTextArea.setBorder(null);
copyrightTextArea.setFocusable(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(24, 0, 24, 0);
mainPanel.add(copyrightTextArea, gridBagConstraints);

closeButton.setMnemonic('C');
closeButton.setText("بستن");
closeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
mainPanel.add(closeButton, gridBagConstraints);

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(mainPanel, gridBagConstraints);
}//


private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
dispose();
}


// Variables declaration - do not modify
private javax.swing.JButton closeButton;
private javax.swing.JTextArea copyrightTextArea;
private javax.swing.JPanel mainPanel;
// End of variables declaration

}
۰



پنجشنبه ۱۲ مارس ۲۰۰۹

کلاس Math

برخی از توابع ریاضی را می تونید در این کلاس پیدا کنید!
خلاصه مطلب را می تونید اینجا و اینجا بخونید!

شنبه ۱۴ فوریهٔ ۲۰۰۹

نرم افزار تبدیل اینچ به سانتی متر

package Intocm;


import java.awt.*;
import javax.swing.*;
import java.awt.event.*; // Needed for ActionListener

//////////////////////////////////////////////////////// class Intocm

class Intocm extends JFrame {
//==================================== constants

private static final double CM = 2.54; //Note 1

//===================== instance variables
private JTextField inch = new JTextField(7); //Note 2

private JTextField cm = new JTextField(7);

//============================= constructor
public Intocm() { //Note 3
// 1... Create/initialize components

JButton convertBtn = new JButton("Convert");

convertBtn.addActionListener(new ConvertBtnListener());

cm.addActionListener(new ConvertBtnListener());
inch.setEditable(false);


// 2... Create content panel, set layout
JPanel content = new JPanel();
content.setLayout(new FlowLayout());

// 3... Add the components to the content panel.
content.add(new JLabel("inch:"));
content.add(cm); // Add input field

content.add(convertBtn); // Add button

content.add(new JLabel("cm:"));
content.add(inch); // Add output field

// 4... Set this window's attributes, and pack it.
setContentPane(content);
pack(); // Layout components.

setTitle("In to Cm");
setSize(400, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null); // Center window.

}

////////////////////////////////////////////////// ConvertBtnListener
class ConvertBtnListener implements ActionListener { //Note 6


public void actionPerformed(ActionEvent e) {
//... Get the value from the dog years textfield.
String cmStr = cm.getText();
//int cmInt = Integer.parseInt(cmStr);

double cmd = Double.parseDouble(cmStr);

double inchValue = cmd * CM; //Note 9

//... Convert to string and set human yrs textfield
inch.setText("" + inchValue);

}
}

//=============================== method main
public static void main(String[] args) {
Intocm window = new Intocm();
window.setVisible(true);
}
}

0
این نرم افزار را با استفاده از کد های اینجا و با مساعدت سرکار خانم شایسته علوی نوشتم!

یکشنبه ۱ فوریهٔ ۲۰۰۹

چگونه از یک فایل بخوانیم یا بر روی یک فایل بنویسیم!

با دو برنامه زیر می توانید بر روی یک فایل یک متن بنویسید و دوباره آن را بخوانید!

import java.io.*;

public class MyFirstFileWritingApp
{
// Main method
public static void main (String args[])
{
// Stream to write file
FileOutputStream fout;

try
{
// Open an output stream
fout = new FileOutputStream ("myfile.txt");

// Print a line of text
new PrintStream(fout).println ("hello world!");

// Close our output stream
fout.close();
}
// Catches any error conditions
catch (IOException e)
{
System.err.println ("Unable to write to file");
System.exit(-1);
}
}


}
0
این برنامه ساده یک فایل متنی میسازد و یک خط از متن روی آن مینویسد!

برای خواندن از روی یک فایل نیز از برنامه زیر استفاده کنید

import java.io.*;

public class MyFirstFileReadingApp
{
// Main method
public static void main (String args[])
{
// Stream to read file
FileInputStream fin;

try
{
// Open an input stream
fin = new FileInputStream ("myfile.txt");

// Read a line of text
System.out.println( new DataInputStream(fin).readLine() );

// Close our input stream
fin.close();
}
// Catches any error conditions
catch (IOException e)
{
System.err.println ("Unable to read from file");
System.exit(-1);
}
}
}
0

پنجشنبه ۸ ژانویهٔ ۲۰۰۹

مراحل ساخت منو menu

۱- یک نوار منو ایجاد کنید.
۲- یک منو ایجاد کنید.
۳- آیتم ها را به منو اضافه کنید.
۴- منو را به نوار منو اضافه کنید.
۵-اگر لازم است مراحل ۲ تا ۴ را تکرار کنید.
۶- نوار منو را به فریم اضافه کنید.

با دستور زیر یک نوار منو ایجاد می شود.

MenuBar myMenubar = new MenuBar(); 0

برای ساختن یک منو از سازنده ( Menu (String title استفاده کنید. مثلآ اگر می خواهید منو های File و Edit را بسازید به روش زیر عمل کنید.

Menu fileMenu = new Menu("File");
Menu editMenu = new Menu("Edit");
0
و به همین صورت منو آیتم ها ساخته می شوند.( MenuItem(String menutext
می توانید منو آیتم ها را داخل منو هایی ایجاد کنید که به آنها تعاق دارند.
MenuItem cut = new MenuItem("Cut");
0
می توانید منو آیتم ها را داخل منو هایی ایجاد کنید که به آنها تعاق دارند.

 Menu editMenu = new Menu("Edit");
MenuItem undo = new MenuItem("Undo")
editMenu.add(undo);
editMenu.addSeparator();
MenuItem cut = new MenuItem("Cut")
editMenu.add(cut);
MenuItem copy = new MenuItem("Copy")
editMenu.add(copy);
MenuItem paste = new MenuItem("Paste")
editMenu.add(paste);
MenuItem clear = new MenuItem("Clear")
editMenu.add(clear);
editMenu.addSeparator();
MenuItem selectAll = new MenuItem("Select All");
editMenu.add(selectAll);
0

متد () addSeparetor یک خط افقی در منو ایجاد می کند تا به طور منطقی وظایف جدا گانه از هم جدا شوند.
بعد از آنکه منو ها ساخته شدند ، آنها را به نوار منو اضافه کنید.
      myMenubar.add(fileMenu);
myMenubar.add(editMenu);
0
در پایان وقتی تمام منو ها با نوار منو اضافه شد، نوار منو را به فریم (مثلآ f ) با استفاده از متد زیر اضافه کنید.

f.setMenuBar(myMenuBar);
0