صفحه 1 از 3 123 آخرآخر
نمایش نتایج 1 تا 40 از 104

نام تاپیک: مجموعه برنامه‌ های نوشته شده به زبان جاوا

  1. #1
    کاربر دائمی آواتار hossein71
    تاریخ عضویت
    شهریور 1387
    محل زندگی
    خونمون-اتاقم-روبروی مانیتور
    پست
    184

    مجموعه برنامه‌ های نوشته شده به زبان جاوا

    سلام خدمت دوستان عزیز و مدیر بخش
    به نظر من لازمه یک تاپیک در بخش تاپیک های اعلان شبیه بخش C++‎‎ ایجاد بشه که هرکسی هربرنامه‌ای با جاوا نوشته قرار بده.اگر چنین تاپیکی در بخش جاوا هست بهتره بصورت تاپیک اعلان در بیاد تا همه بتونن به راحتی بهش دسترسی داشته باشن.
    بنده در جاوا تازه کار هستم.اولین برنامه(یا تمرین) خودمو که نوشتم براتون قرار میدم.

    این برنامه یک عدد از مجموعه اعداد طبیعی را دریافت می‌کند و تمام اعداد اول که بین 1 و عدد گرفته شده قرار دارد را در خروچی چاپ می‌کند.
    کلاس PrimeNumber:

    import java.util.Scanner;
    public class PrimeNumber {

    public static void main(String[] args) {
    Scanner input = new Scanner( System.in );
    Search ObjectSearch=new Search();
    System.out.println("What range number?");
    int in=input.nextInt();
    System.out.println(".................");
    ObjectSearch.FindPrime(in);
    System.out.printf(".............\nCount is %s\n",ObjectSearch.CPrime());
    }
    }


    کلاس Search:

    public class Search {
    private int CountPrime=0;
    public void FindPrime(int arg)
    {
    int Number[]=new int[arg];
    for (int Count=2;Count<arg;Count++){
    Number[Count]=Count;
    }
    for (int del=2;del<=(arg/2);del++){
    for (int Count=del;Count<arg;Count++){
    if (Number[Count]%del==0 & Number[Count]!=del)
    Number[Count]=-1;
    }

    }
    for (int Count=2;Count<arg;Count++){
    if (Number[Count]!=-1){
    CountPrime++;
    System.out.println(Number[Count]);
    }
    }
    }
    public int CPrime()
    {
    return CountPrime;
    }
    }


    تصویری از خروجی:

    2-16-2012 7-14-43 PM.jpg

    Prime Number.rar

    ....................................
    بعد از ویرایش:
    دوستانی که از netbeans استفاده نمیکنند میتونند دوتا کلاس خودشون درست کنند و با توجه به کد برنامه نامگذاری کنند. سپس کدها رو داخل کلاس مربوطه کپی کنند.
    آخرین ویرایش به وسیله hossein71 : پنج شنبه 04 اسفند 1390 در 23:38 عصر

  2. #2

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    سلام به همه.
    نظر من هم همینه.
    همچین تایپکی برای بخش جاوا لازمه.
    منم در خواست دارم که این تایپک به صورت اعلان در بیاد.
    با تشکر

  3. #3
    کاربر دائمی آواتار hossein71
    تاریخ عضویت
    شهریور 1387
    محل زندگی
    خونمون-اتاقم-روبروی مانیتور
    پست
    184

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    ضمن تشکر از جناب spiderman200700 ولی انگار دوستان خیلی تمایلی به گذاشتن برنامه‌های خودشون ندارند.
    لطفا دوستان برنامه‌هایی که نوشتند رو در این تاپیک قرار بدند(مخصوصا دوستانی که در جاوا دستی برآتش دارند).

  4. #4

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    سلام
    با تجربیات قبلی در این موارد سایر دوستان منتظرن تا ببینن سطح برنامه هایی که بقیه میذارن در چه اندازس.
    اونایی که مبتدی هستن احتیاط می کنن تا برنامه های زیادی ساده نذارن.
    حرفه ای ها هم شاید می خوان حد و اندازه اینجا رو ببینن.
    بهر حال اون تاپیک از سی پلاس پلاس برا این زود رشد کرد که یه عده نه چندان کمی که خیلی حرفه ای هم نبودن همه جور برنامه ای نوشتن.
    من خودم واقعا ازون تاپیک استفاده کردم.

    قرار هم نیست برنامه های خیلی حرفه ای بی مخاطب بمونه همونطور که برنامه های ساده بدون مخاطب نیستن.
    چرتکه ها رو بذارید کنار.

  5. #5

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    سلام دوستان.این ماشین حساب هست که اعداد رو در دو خط میگیره و عملگرها رو هم در چهار حالت اصلی جمع و تفریق و ضرب و تقسیم میشناسه.خودم نوشتمش .فکر کنم خیلی ساده اس اما امیدوارم بتونه مفید باشه
    import java.util.Scanner;
    public class Calculatrice {

    public static void main(String args[]) {

    Scanner hossein=new Scanner(System.in);
    float num1,num2,result=0;
    char x;
    num1=hossein.nextFloat();
    num2 = hossein.nextFloat();
    System.out.println("enter your operation");
    x = hossein.next().charAt(0);
    if (x== '+') {
    result = num1+num2;
    }
    else if (x== '-') {
    result = num1-num2;
    }
    else if (x== '*') {
    result = num1*num2;
    }
    else if (x== '/') {
    result = num1/num2;
    }
    else {

    System.out.println("this is not operator");
    }
    System.out.println("the result is");

    System.out.println(result);

    }
    }

  6. #6

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    اینم اولین برنامه ی من.
    کوچیک و سادس ولی از هیچی بهتره.

    ماتریس ترانهاده

    public class TransposedMatrix {

    public static void main(String args[]) {
    int k = 0;
    int matrix[][] = new int[4][4];
    int mt[][]=new int[4][4];
    for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[i].length; j++) {
    matrix[i][j] = k++;
    if(k>9){
    k=0;
    }
    System.out.print(" " + matrix[i][j]);
    }
    System.out.println();
    }

    System.out.println();
    System.out.println();
    for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[0].length; j++) {
    mt[j][i] = matrix[i][j];
    }
    }
    for (int i = 0; i < mt.length; i++) {
    for (int j = 0; j < mt[i].length; j++) {
    System.out.print(" " + mt[i][j]);
    }
    System.out.println();
    }
    }
    }
    آخرین ویرایش به وسیله spiderman200700 : پنج شنبه 04 اسفند 1390 در 23:00 عصر

  7. #7

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    یه برنامه برای رسم این شکل:
      *   
    ***
    *****
    *****
    ***
    *


    package javaclass;

    public class UpDownTriangle {

    static int n = 6;
    static int FILL = 1;
    static int FIRST = 0;

    public static void main(String args[]) {

    if (n % 2 == 0) {
    FIRST = n / 2;
    } else {
    FIRST = (int) (n / 2) + 1;
    }
    int SPASE = FIRST - 1;
    int i = 0;
    for (i = 0; i < FIRST; i++) {
    fillRow(new char[n], SPASE, FILL);
    if (n % 2 == 0 && i == FIRST - 1) {
    fillRow(new char[n], SPASE, FILL);
    } else if (i < FIRST - 1) {
    SPASE--;
    FILL += 2;
    }
    }

    for (i = FIRST; i < n; i++) {
    SPASE++;
    FILL -= 2;
    fillRow(new char[n], SPASE, FILL);
    }
    }

    public static void fillRow(char[] row, int SPASE, int FILL) {
    for (int i = SPASE; i < FILL + SPASE; i++) {
    row[i] = '*';
    }
    System.out.println(row);
    }
    }

  8. #8

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    رسم خطوط مورب زیبا.
    با تغییر دادن اندازه ی پنجره ، اندازه ی خطوط به تناسب تغییر می کنه.
    این برنامه رو به صورت Applet نوشتم.

    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.Graphics;

    public class Lines extends Applet {

    int w = 0;
    int h = 0;
    int x1 = 0;
    int y1 = 0;
    int x2 = 0;
    int y2 = 0;

    public void init() {
    setSize(800, 600);
    setBackground(Color.PINK);
    }

    public void paint(Graphics g) {
    w = getSize().width;
    h = getSize().height;
    leftDown(g, w, h, w / 30, h / 30);
    leftUp(g, w, h, w / 30, h / 30);
    rightDown(g, w, h, w / 30, h / 30);
    rightUp(g, w, h, w / 30, h / 30);
    }

    public void leftDown(Graphics g, int w, int h, int wp, int hp) {
    x1 = w;
    y1 = h;
    x2 = 0;
    y2 = h;
    g.setColor(Color.BLACK); // Drawing line color is red
    for (int i = 0; i < w/5; i++) {
    g.drawLine(x1, y1, x2, y2);
    x1 -= wp;
    y2 -= hp;
    }
    }

    public void leftUp(Graphics g, int w, int h, int wp, int hp) {
    x1 = w;
    y1 = 0;
    x2 = 0;
    y2 = 0;
    g.setColor(Color.BLACK); // Drawing line color is red
    for (int i = 0; i < w/5; i++) {
    g.drawLine(x1, y1, x2, y2);
    x1 -= wp;
    y2 += hp;
    }
    }

    public void rightDown(Graphics g, int w, int h, int wp, int hp) {
    x1 = 0;
    y1 = 0;
    x2 = w;
    y2 = 0;
    g.setColor(Color.BLACK); // Drawing line color is red
    for (int i = 0; i < w/5; i++) {
    g.drawLine(x1, y1, x2, y2);
    x1 += wp;
    y2 += hp;
    }
    }

    public void rightUp(Graphics g, int w, int h, int wp, int hp) {
    x1 = 0;
    y1 = h;
    x2 = w;
    y2 = h;
    g.setColor(Color.BLACK); // Drawing line color is red
    for (int i = 0; i < w/5; i++) {
    g.drawLine(x1, y1, x2, y2);
    x1 += wp;
    y2 -= hp;
    }
    }
    }
    عکس های ضمیمه عکس های ضمیمه
    آخرین ویرایش به وسیله spiderman200700 : پنج شنبه 04 اسفند 1390 در 22:59 عصر

  9. #9

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    رسم اشکال با موس.
    package javaclass;

    import java.awt.BorderLayout;
    import java.awt.Point;
    import java.awt.Graphics;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;

    public class PaintPanel extends JPanel {

    private int pointCount = 0; // count number of points
    // array of 10000 java.awt.Point references
    private Point points[] = new Point[10000];

    // set up GUI and register mouse event handler
    public PaintPanel() {

    // handle frame mouse motion event
    addMouseMotionListener(
    new MouseMotionAdapter() { // anonymous inner class {
    // store drag coordinates and repaint
    public void mouseDragged(MouseEvent event) {
    if (pointCount < points.length) {
    points[ pointCount] = event.getPoint(); // find point
    pointCount++; // increment number of points in array
    repaint(); // repaint JFrame
    } // end if
    } // end method mouseDragged
    } // end anonymous inner class
    ); // end call to addMouseMotionListener
    } // end PaintPanel constructor

    // draw oval in a 4-by-4 bounding box at specified location on window
    public void paintComponent(Graphics g) {
    super.paintComponent(g); // clears drawing area
    // draw all points in array
    for (int i = 0; i < pointCount; i++) {
    g.fillOval(points[ i].x, points[ i].y, 20, 20);
    }
    } // end method paintComponent

    public static void main(String args[]) {
    // create JFrame
    JFrame application = new JFrame("A simple paint program");
    PaintPanel paintPanel = new PaintPanel(); // create paint panel
    application.add(paintPanel, BorderLayout.CENTER); // in center
    // create a label and place it in SOUTH of BorderLayout
    application.add(new JLabel("Drag the mouse to draw"),
    BorderLayout.SOUTH);
    application.setDefaultCloseOperation(JFrame.EXIT_O N_CLOSE);
    application.setSize(400, 200); // set frame size
    application.setVisible(true); // display frame
    } // end main
    } // end class PaintPanel
    عکس های ضمیمه عکس های ضمیمه

  10. #10

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

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

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;

    public class PopupTest extends JFrame
    {
    private JMenuItem items[];
    private Color colorValues[] = { Color.blue, Color.yellow, Color.red };

    public PopupTest()
    {
    super( "Using JPopupMenus" );

    final JPopupMenu popupMenu = new JPopupMenu();
    ItemHandler handler = new ItemHandler();
    String colors[] = { "Blue", "Yellow", "Red" };
    ButtonGroup colorGroup = new ButtonGroup();
    items = new JMenuItem[ 3 ];

    // construct each menu item and add to popup menu; also
    // enable event handling for each menu item
    for ( int i = 0; i < items.length; i++ )
    {
    items[ i ] = new JMenuItem( colors[ i ] );
    popupMenu.add( items[ i ] );
    colorGroup.add( items[ i ] );
    items[ i ].addActionListener( handler );
    }

    getContentPane().setBackground( Color.white );

    // define a MouseListener for the window that displays
    // a JPopupMenu when the popup trigger event occurs
    addMouseListener( new MouseAdapter()
    {
    public void mousePressed( MouseEvent e )
    {
    checkForTriggerEvent( e );
    }

    public void mouseReleased( MouseEvent e )
    {
    checkForTriggerEvent( e );
    }

    private void checkForTriggerEvent( MouseEvent e )
    {
    if ( e.isPopupTrigger() )
    popupMenu.show( e.getComponent(), e.getX(), e.getY() );
    }
    } );

    setSize( 300, 200 );
    show();
    }

    public static void main( String args[] )
    {
    PopupTest app = new PopupTest();

    app.addWindowListener( new WindowAdapter()
    {
    public void windowClosing( WindowEvent e )
    {
    System.exit( 0 );
    }
    });
    }

    private class ItemHandler implements ActionListener
    {
    public void actionPerformed( ActionEvent e )
    {
    // determine which menu item was selected
    for ( int i = 0; i < items.length; i++ )
    if ( e.getSource() == items[ i ] )
    {
    getContentPane().setBackground( colorValues[ i ] );
    repaint();
    return;
    }
    }
    }
    }

  11. #11

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    یه برنامه برای ایجاد Rule (یا به قول خودمون خط کش) در برنامه ها.
    اینو از سایت Oracle گرفتم.گفتم شاید جالب باشه.
    ما معمولا خیلی کم از کلاس Rule استفاده می کنیم.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;


    public class ScrollDemo extends JPanel
    implements ItemListener {
    private Rule columnView;
    private Rule rowView;
    private JToggleButton isMetric;
    private ScrollablePicture picture;

    public ScrollDemo() {
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    //Get the image to use.
    ImageIcon bee = createImageIcon("images/flyingBee.jpg");

    //Create the row and column headers.
    columnView = new Rule(Rule.HORIZONTAL, true);
    rowView = new Rule(Rule.VERTICAL, true);

    if (bee != null) {
    columnView.setPreferredWidth(bee.getIconWidth());
    rowView.setPreferredHeight(bee.getIconHeight());
    } else {
    columnView.setPreferredWidth(320);
    rowView.setPreferredHeight(480);
    }

    //Create the corners.
    JPanel buttonCorner = new JPanel(); //use FlowLayout
    isMetric = new JToggleButton("cm", true);
    isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11));
    isMetric.setMargin(new Insets(2,2,2,2));
    isMetric.addItemListener(this);
    buttonCorner.add(isMetric);

    //Set up the scroll pane.
    picture = new ScrollablePicture(bee, columnView.getIncrement());
    JScrollPane pictureScrollPane = new JScrollPane(picture);
    pictureScrollPane.setPreferredSize(new Dimension(300, 250));
    pictureScrollPane.setViewportBorder(
    BorderFactory.createLineBorder(Color.black));

    pictureScrollPane.setColumnHeaderView(columnView);
    pictureScrollPane.setRowHeaderView(rowView);

    //Set the corners.
    //In theory, to support internationalization you would change
    //UPPER_LEFT_CORNER to UPPER_LEADING_CORNER,
    //LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and
    //UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER. In practice,
    //bug #4467063 makes that impossible (in 1.4, at least).
    pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT _CORNER,
    buttonCorner);
    pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT _CORNER,
    new Corner());
    pictureScrollPane.setCorner(JScrollPane.UPPER_RIGH T_CORNER,
    new Corner());

    //Put it in this panel.
    add(pictureScrollPane);
    setBorder(BorderFactory.createEmptyBorder(20,20,20 ,20));
    }

    public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
    //Turn it to metric.
    rowView.setIsMetric(true);
    columnView.setIsMetric(true);
    } else {
    //Turn it to inches.
    rowView.setIsMetric(false);
    columnView.setIsMetric(false);
    }
    picture.setMaxUnitIncrement(rowView.getIncrement() );
    }

    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
    java.net.URL imgURL = ScrollDemo.class.getResource(path);
    if (imgURL != null) {
    return new ImageIcon(imgURL);
    } else {
    System.err.println("Couldn't find file: " + path);
    return null;
    }
    }

    /**
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    */
    private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("ScrollDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    //Create and set up the content pane.
    JComponent newContentPane = new ScrollDemo();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
    }

    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }
    });
    }
    }
    آخرین ویرایش به وسیله spiderman200700 : پنج شنبه 04 اسفند 1390 در 23:03 عصر

  12. #12

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    مرتب سازی درجی :
    public class InsertionSort {

    public static void main(String args[]) {
    print(insertionSort(new int[]{3, 2, -5, 8, 5, 10, 0, 29, -1}));
    }

    public static int[] insertionSort(int Numbers[]) {
    int i, j, x;
    for (i = 0; i < Numbers.length; i++) {
    x = Numbers[i];
    j = i - 1;
    for (; j >= 0 && Numbers[j] > x; j--) {
    Numbers[j + 1] = Numbers[j];
    }
    Numbers[j + 1] = x;
    }
    return Numbers;
    }

    public static void print(int Numbers[]) {
    for (int Number : Numbers) {
    System.out.print(Number + " ");
    }
    System.out.println();
    }
    }

  13. #13

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    از دوستان تقاضا دارم که برنامه هاشونو بدون چشم داشت اینجا بذارن.
    فرق نمیکنه برنامه کوچیک باشه یا بزرگ باشه. فقط سعی کنید تکراری نباشه.
    دوستان کمک کنید که تالار جاوا یه کم قوی تر بشه . این تالار هر چقدر قوی تر بشه به نفع خودمونه.
    وقتی کسی کدی رو اینجا قرار میده ممکنه به درد ده ها نفر بخوره.
    پس لطفا همکاری کنید.
    با تشکر.
    آخرین ویرایش به وسیله spiderman200700 : شنبه 13 اسفند 1390 در 23:47 عصر

  14. #14

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    نقل قول نوشته شده توسط spiderman200700 مشاهده تاپیک
    برنامه ی JDownload Manager V1.0 همان برنامه یDownload Manager است، که توسط بنده،در پست 13 همین تایپک قرار گرفت.با این تفاوت که در JDownload Manager V1.0 یک سری امکانات جدید به برنامه اضافه شده و هدف از انشار آن، گسترش یک نرم افزار منبع باز جاوا ، توسط ایرانیان عزیز است.
    با تشکر از شما دوست عزیز،
    با اجازتون امکان کوچکی رو به برنامه شما اضافه کردم که میشه با استفاده از Socks proxy هم دانلود کرد.
    متاسفانه هنوز همه ی Exception ها رو handle نکردم اما اگر فایل کانفیگ دستکاری نشود و کاربر اطلاعات درست وارد کند برنامه مشکلی نخواهد داشت.
    شاید کد هایی که نوشته ام خیلی اصولی و بهینه نباشد پس لطف کنید خودتون اگر لازم دیدید تغییرش بدید.
    به نظرم این برنامه پتانسیل این رو داره که امکانات زیادی بهش اضافه بشه و تاپیکی جدا داشته باشد.

    JDownloadManagerV1.00.rar

  15. #15

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    سلام.
    جناب saban56 ، خیلی عالیه.کد هاتون هم خوبه.
    اگه زحمت مدیریت Exeption ها رو هم بکشید ، که دیگه عالیه عالی میشه. هر چند تعداد Exeption هایی که ممکنه پیش بیاد و مدیریت نشده باشه خیلی کمه.
    پروکسی سرور خیلی امکان عالییه.
    و من هم با شما کاملا موافقم. این برنامه میتونه تبدیل به یه برنامه ی کاملا حرفه ای بشه. البته با کمک همه ی دوستان جاوا کار.
    واقعا دستت درد نکنه و خسته نباشی.


    همه ی ما بازم منتظر ایده های دوستان خلاق هستیم.
    لطفا این برنامه رو گسترش بدید.
    با تشکر
    آخرین ویرایش به وسیله spiderman200700 : شنبه 12 فروردین 1391 در 21:56 عصر

  16. #16

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    من برای برنامه های خودم احتیاج داشتم که از یک فایل بیت به بیت بخونم و بنویسم...شاید به دردتون بخوره :)
    البته این رو از جایی پیدا کرده بودم و یه سری ویرایش کوچیک کردم ;)



    /*
    *
    * Class allowing to read and write bit per bit
    *
    *
    * Author: parmenti @ sfs . uni-tuebingen . de
    *
    */


    import java.io.*;
    public class BitWriter {

    FileOutputStream f;
    int nb_bits; // number of occupied bits in the buffer
    int aByte; //our buffer, we only write bits when we gathered 8 bits

    BitWriter(String file , FileOutputStream f) throws IOException {
    this.f = f;
    nb_bits = 0;
    aByte = 0;
    }

    void writeBit(int b) throws IOException {
    // b must be in {0,1} !!
    nb_bits++;

    // in all cases, we use the shift operators to append ...
    if (b==0) {
    // ... either a 0 (shift example: 1 << 2 == 100) ...
    aByte = aByte << 1;
    } else {
    // ... or a 1 (| is the logical or: 1|0 == 1)
    aByte = aByte << 1 | 1;
    }
    if (nb_bits == 8) {
    // the buffer is full, we write to disc

    System.out.print("writing " + aByte);
    System.out.println(" -- \t" + Integer.toBinaryString(aByte));
    f.write(aByte);
    // and reset
    nb_bits = 0;
    aByte = 0;
    }

    }

    void flush() throws IOException {
    if (nb_bits != 0) {
    // we append the necessary 0s
    aByte = aByte << (8-nb_bits);
    f.write(aByte);
    }
    // after flushing the buffer, we reset
    aByte = 0;
    nb_bits = 0;
    f.flush();
    }

    void close() throws IOException {
    f.close();
    }
    }




    /*
    *
    * Class allowing to read and write bit per bit
    *
    *
    * Author: parmenti @ sfs . uni-tuebingen . de
    *
    */


    import java.io.*;

    public class BitReader {
    FileInputStream f;
    int bits; // the buffer
    int mask; // the mask will start with 10000000 and
    // be right-shifted to read the stream from left to right

    BitReader(String file) throws IOException{
    f = new FileInputStream(file);
    bits = 0;
    mask = 0;
    }

    int readBit() throws IOException{
    // method that reads the next bit in the input stream

    if (mask == 0) {
    // the buffer is empty (the right-shifts have gone throught the 8 bits)
    // we feed the buffer with the next byte
    bits = f.read();
    // the mask is (re)set to the hexadecimal value 80 = 8.16 = 128 = 10000000
    mask = 0x80;
    // if the end of the stream is reached, we return -1
    if (bits==-1) return(-1);
    }

    if ((bits & mask) == 0) {
    // the current position highlighted by the mask is 0 (0 & 1 == 0)

    // right-shift for next reading
    mask = mask >> 1;
    return 0;
    }
    else {
    // the current position highlighted by the mask is 1 (1 & 1 == 1)

    // right-shift for next reading
    mask = mask >> 1;
    return 1;
    }
    }

    void close() throws IOException {
    f.close();
    }
    }
    آخرین ویرایش به وسیله halghe106 : دوشنبه 14 فروردین 1391 در 10:40 صبح

  17. #17

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    همچین تاپیکی در بخش جاوا SE داشتیم : لینک

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

  18. #18

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    نقل قول نوشته شده توسط هانی هاشمی مشاهده تاپیک
    همچین تاپیکی در بخش جاوا SE داشتیم : لینک

    اما به خاطر کم لطفیه دوستان به روز نشد
    درسته.اما امیدوارم این تایپک به سرنوشت قبلی دچار نشه.
    من خودم هر برنامه ای که فکر کنم به درد بقیه میخوره رو اینجا قرار میدم. امیدوارم بقیه ی دوستان هم همین کار رو بکنن.

  19. #19

    نقل قول: کمک فوری

    با تشکر از همه.
    کمک فوری/
    من میخام این شکل رو با eclips رسم کنم ولی خیلی مشکله حالا شاید من بلد نباشم.

    هر کی با eclips کار کرده لطف کنه این شکل رو برام ترسیم کنه.به وسیله کد در eclips
    ممنون.
    */شکل رو ضمیمه کردم/*rasm.JPG

  20. #20

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    نمایش متون با ابزار های سطح پایین جاوا.
    با کلیک بر روی پنجره ی برنامه تراز بندی متن تغییر میکنه.

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;

    public class TextLayout extends JPanel {

    private static final int LEFT_ALIGN = 0;
    private static final int RIGHT_ALIGN = 1;
    private static final int CENTER_ALIGN = 2;
    private static final int LEFT_RIGHT_ALIGN = 3;
    protected int align;
    private Dimension d;
    private Font font;
    private FontMetrics fm;
    private int fontSize;
    private int fh, bl;
    private int space;
    private String text = "Just as you would use your hands to interact "
    + "with objects in the physical world, you can use your mouse to"
    + " interact with items on your computer screen . You can move objects"
    + ", open them, change them, throw them away, and perform other actions,"
    + " all by pointing and clicking with your mouse";

    public TextLayout() {
    setBackground(Color.ORANGE);

    try {
    fontSize = 20;
    } catch (NumberFormatException e) {
    fontSize = 14;
    }
    align = LEFT_ALIGN;
    addMouseListener(new MyMouseAdapter(this));
    }

    @Override
    protected void paintComponent(Graphics g) {
    update(g);
    }

    @Override
    public void update(Graphics g) {
    d = getSize();
    g.setColor(getBackground());
    g.fillRect(0, 0, d.width, d.height);
    if (font == null) {
    font = new Font("tahoma",
    Font.PLAIN, fontSize);
    }
    g.setFont(font);
    if (fm == null) {
    fm = g.getFontMetrics();
    bl = fm.getAscent();
    fh = bl + fm.getDescent();
    space = fm.stringWidth(" ");
    }
    g.setColor(Color.black);
    StringTokenizer st = new StringTokenizer(text);
    int x = 0;
    int nextx;
    int y = 0;
    String word, sp;
    int wordCount = 0;
    String line = "";
    while (st.hasMoreTokens()) {
    word = st.nextToken();

    if (word.equals(".")) {
    drawString(g, line, wordCount,
    fm.stringWidth(line), y + bl);
    line = "";
    wordCount = 0;
    x = 0;
    y = y + (fh * 2);
    } else {
    int w = fm.stringWidth(word);
    if ((nextx = (x + space + w)) > d.width) {
    drawString(g, line, wordCount,
    fm.stringWidth(line), y + bl);
    line = "";
    wordCount = 0;
    x = 0;
    y = y + fh;
    }
    if (x != 0) {
    sp = " ";
    } else {
    sp = "";
    }
    line = line + sp + word;
    x = x + space + w;
    wordCount++;
    }
    }
    drawString(g, line, wordCount, fm.stringWidth(line), y + bl);
    }

    public void drawString(Graphics g, String line,
    int wc, int lineW, int y) {
    switch (align) {
    case LEFT_ALIGN:
    g.drawString(line, 0, y);
    break;
    case RIGHT_ALIGN:
    g.drawString(line, d.width - lineW, y);
    break;
    case CENTER_ALIGN:
    g.drawString(line, (d.width - lineW) / 2, y);
    break;
    case LEFT_RIGHT_ALIGN:
    if (lineW < (int) (d.width * .75)) {
    g.drawString(line, 0, y);
    } else {
    int toFill = (int) ((d.width - lineW) / wc);

    int nudge = d.width - lineW - (toFill * wc);
    int s = fm.stringWidth(" ");
    StringTokenizer st = new StringTokenizer(line);
    int x = 0;
    while (st.hasMoreTokens()) {
    String word = st.nextToken();
    g.drawString(word, x, y);
    if (nudge > 0) {
    x = x + fm.stringWidth(word) + space + toFill + 1;
    nudge--;
    } else {
    x = x + fm.stringWidth(word) + space + toFill;
    }
    }
    }
    break;
    }
    }

    public static void main(String args[]) {
    JFrame frame = new JFrame("best");
    frame.add(new TextLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(600, 400);
    frame.setVisible(true);
    }
    }

    class MyMouseAdapter extends MouseAdapter {

    TextLayout tl;

    public MyMouseAdapter(TextLayout tl) {
    this.tl = tl;
    }

    public void mouseClicked(MouseEvent me) {
    tl.align = (tl.align + 1) % 4;
    tl.repaint();
    }
    }
    آخرین ویرایش به وسیله spiderman200700 : پنج شنبه 22 تیر 1391 در 01:46 صبح

  21. #21
    کاربر جدید آواتار sara.sherafati
    تاریخ عضویت
    فروردین 1391
    محل زندگی
    اصفهانــــــ
    سن
    32
    پست
    28

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    جمع 10 تا عدد
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package ex1;

    /**
    *
    * @author sara
    */
    public class sum {
    public static void main(String args[]){
    int sum=0;
    // int sum=0,i=1;
    // if (i<=100) {
    // sum=i+sum;
    // i=i+1;
    //
    // }
    // System.out.println("sum ="+sum);
    //
    for (int i = 1; i <= 1000; i++) {
    sum=sum+i;
    }
    System.out.println("sum ="+sum);

    }

    }

  22. #22
    کاربر جدید آواتار sara.sherafati
    تاریخ عضویت
    فروردین 1391
    محل زندگی
    اصفهانــــــ
    سن
    32
    پست
    28

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    قسط ماهیانه

    import java.util.Scanner;

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author sara
    */
    public class ghest {
    public static void main(String[] args) {
    Scanner sara=new Scanner(System.in);
    int mounth;
    double vam,karmozd,sood,mablagh,ghest;
    System.out.println("cheghadr vam mikhay:");
    vam=sara.nextDouble();
    System.out.println("dar che modat:");
    mounth=sara.nextInt();
    System.out.println("che meghdar kamrmozdeshe:");
    karmozd=sara.nextDouble();
    sood=(vam*karmozd*(1+mounth))/2400;
    mablagh=vam+mounth;
    ghest=mablagh/mounth;

    System.out.println("ghest = "+ghest);




    }

    }

  23. #23
    کاربر جدید
    تاریخ عضویت
    مهر 1391
    محل زندگی
    تهران
    پست
    22

    Lightbulb نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    سلام یه پروژه به زبان جاوا میخوام با موضوع زیر

    برنامه ایی که یک رشته از کاربر بگیرد
    1- تعداد کلمات آن را نشان دهد
    2- بتواند اندیس کلمه خاص را نشان دهد

    این برنامه باید بتواند یک جمله را بگیرد مثل:hello my name is noura karimi and i love computer
    خروجی اول بگه این جمله طولش چقدره یا همان تعداد کلماتش
    برای خروجی دوم بیات از کاربر بپرسه کلمه خاص شما چیه مثلا وارد میشه noura که باید اندیس این کلمه را برگرداند

    خواهش میکنم کمکم کنید

  24. #24
    کاربر جدید
    تاریخ عضویت
    اسفند 1391
    محل زندگی
    زیر آسمون خدا
    سن
    32
    پست
    17

    Smile سورس کدهای آماده جاوا(نمونه برنامه های ساده از جاوا)

    برنامه ای به زبان جاوا بنویسید که یک رشته از ورودی گرفته و اگر طول رشته زوج باشد و در نیمه اول رشته کلمه ali و در نیمه دوم رشته کلمه reza وجود داشته باشد yes را نمایش دهد

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package ex1;

    /**
    *
    * @author pars
    */import java.util.*;
    public class Ex1 {

    /**
    * @param args the command line arguments
    */
    static Scanner in = new Scanner ( System.in ) ;
    public static void main(String[] args) {
    // TODO code application logic here
    String str1,str2,str3;
    int a,b,j=0,c;
    System.out.print("Enter a string : ");
    str1 = in.next() ;
    c = str1.length();
    if(str1.length()%2 == 0)
    {
    str2=str1.substring(0, c/2);
    str3=str1.substring(c/2,c);
    a = str2.indexOf("ali") ;//index returns -1 on failure.
    if ( a >= 0 )
    { j++;
    System.out.println(" ali find "); }
    b = str3.indexOf("reza") ;//index returns -1 on failure.
    if ( b >= 0 )
    {
    j++;
    System.out.println(" reza find ");
    }
    if (j>=2)
    System.out.println(" YES ");
    }
    }
    }




    خروجی :

    run:
    Enter a string : aliareza
    ali find
    reza find
    YES
    BUILD SUCCESSFUL (total time: 16 seconds)

  25. #25
    کاربر جدید
    تاریخ عضویت
    اسفند 1391
    محل زندگی
    زیر آسمون خدا
    سن
    32
    پست
    17

    Smile سورس کدهای آماده جاوا(نمونه برنامه های ساده از جاوا)

    برنامه ای به زبان جاوا بنویسید که 10 نمره یک دانشجو را گرفته و معدلش را حساب کند( توسط آرایه)

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package ex2;

    /**
    *
    * @author pars
    */
    import java.util.*;
    public class Ex2 {

    /**
    * @param args the command line arguments
    */
    static Scanner console = new Scanner (System.in);
    public static void main(String[] args) {
    // TODO code application logic here
    double items [] = new double[10];
    int i;
    double sum;
    sum = 0 ;
    System.out.println(" **** Please enter student grades ****");
    for(i = 0; i< items.length; i++)
    {
    items[i] = console.nextDouble();
    sum += items[i];
    }
    System.out.println("Average of class is : " + sum/10);
    }
    }



    خروجی:
    run:
    **** Please enter student grades ****
    19
    18
    17
    20
    19
    19
    20
    18
    17
    18
    Average of class is : 18.5
    BUILD SUCCESSFUL (total time: 22 seconds)



    به قرعان نمرات خودم بود !!!

  26. #26
    کاربر جدید
    تاریخ عضویت
    اسفند 1391
    محل زندگی
    زیر آسمون خدا
    سن
    32
    پست
    17

    Smile سورس کدهای آماده جاوا(نمونه برنامه های ساده از جاوا)

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


    خط اول 7 تا جا خالی داره و خط های بعدی دوتا دوتا کم میشه یعنی بعدی 5 تا جا خالی داره
    به خاطر اجرایه کدهای اچ تی ام ال در خط 20 کد عوض شده است به تصویر نگاه کنید و آن را تصحیح کنید :

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:\
    String output = "<html><pre>", out = "";
    for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= i; j++) {
    output += "*";
    }
    for (int k = 9 - (2 * i); k >= 1; k--) {
    output += " ";
    }
    if (i != 5) {
    for (int s = 1; s <= i; s++) {
    output += "*";
    }
    } else {
    for (int s = 1; s < i; s++) {
    output += "*";
    }
    }
    output += "<br>";
    }
    out = output + "</pre></html>";
    this.jLabel1.setText(out);
    }

    خروجی : ( این مثال فقط یه بوتن نمایش داره و یه لیبل )

  27. #27
    کاربر جدید
    تاریخ عضویت
    اسفند 1391
    محل زندگی
    زیر آسمون خدا
    سن
    32
    پست
    17

    Smile نقل قول: سورس کدهای آماده جاوا(نمونه برنامه های ساده از جاوا)

    برنامه یک ماشین حساب که به جزء اعمال جبری اعمال توان و لگاریتم و نسبت های مثلثاتی و جذر و قدر مطلق را نیز انجام میدهد.موقع بسته شدن پیام میدهد که آیا مطمئن هستید و دکمه های Yes و No دارد.

    لینک دانلود پروژه: اینجا کلیک کنید

    قسمت کنسولی :


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author Gharekhani
    */
    public class main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here
    myGUIform f = new myGUIform();
    f.setVisible(true);
    }
    }
    قسمت ویندوزی :

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /*
    * myGUIform.java
    *
    * Created on Mar 11, 2013, 12:41:23 PM
    */
    /**
    *
    * @author Gharekhani
    */
    import javax.swing.JOptionPane;
    public class myGUIform extends javax.swing.JFrame {

    /** Creates new form myGUIform */
    public myGUIform() {
    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.
    */
    @SuppressWarnings("unchecked")
    //
    private void initComponents() {

    answer = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jButton4 = new javax.swing.JButton();
    jButton5 = new javax.swing.JButton();
    jButton6 = new javax.swing.JButton();
    jButton7 = new javax.swing.JButton();
    jButton8 = new javax.swing.JButton();
    jButton9 = new javax.swing.JButton();
    jButton10 = new javax.swing.JButton();
    jButton11 = new javax.swing.JButton();
    jButton12 = new javax.swing.JButton();
    jButton13 = new javax.swing.JButton();
    jButton14 = new javax.swing.JButton();
    jButton15 = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jButton16 = new javax.swing.JButton();
    jButton17 = new javax.swing.JButton();
    jButton18 = new javax.swing.JButton();
    jButton19 = new javax.swing.JButton();
    jButton20 = new javax.swing.JButton();
    jButton21 = new javax.swing.JButton();
    jButton22 = new javax.swing.JButton();
    jButton23 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowOpened(java.awt.event.WindowEvent evt) {
    formWindowOpened(evt);
    }
    });

    answer.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    answerActionPerformed(evt);
    }
    });

    jButton1.setText("1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    }
    });

    jButton2.setText("2");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton2ActionPerformed(evt);
    }
    });

    jButton3.setText("3");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton3ActionPerformed(evt);
    }
    });

    jButton4.setText("4");
    jButton4.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton4ActionPerformed(evt);
    }
    });

    jButton5.setText("5");
    jButton5.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton5ActionPerformed(evt);
    }
    });

    jButton6.setText("6");
    jButton6.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton6ActionPerformed(evt);
    }
    });

    jButton7.setText("7");
    jButton7.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton7ActionPerformed(evt);
    }
    });

    jButton8.setText("8");
    jButton8.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton8ActionPerformed(evt);
    }
    });

    jButton9.setText("9");
    jButton9.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton9ActionPerformed(evt);
    }
    });

    jButton10.setText("0");
    jButton10.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton10ActionPerformed(evt);
    }
    });

    jButton11.setText("+");
    jButton11.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton11ActionPerformed(evt);
    }
    });

    jButton12.setText("-");
    jButton12.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton12ActionPerformed(evt);
    }
    });

    jButton13.setText("*");
    jButton13.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton13ActionPerformed(evt);
    }
    });

    jButton14.setText("/");
    jButton14.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton14ActionPerformed(evt);
    }
    });

    jButton15.setText("=");
    jButton15.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton15ActionPerformed(evt);
    }
    });

    jButton16.setText("pow");
    jButton16.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton16ActionPerformed(evt);
    }
    });

    jButton17.setText("abs");
    jButton17.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton17ActionPerformed(evt);
    }
    });

    jButton18.setText("log");
    jButton18.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton18ActionPerformed(evt);
    }
    });

    jButton19.setText("sqrt");
    jButton19.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton19ActionPerformed(evt);
    }
    });

    jButton20.setText("cos");
    jButton20.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton20ActionPerformed(evt);
    }
    });

    jButton21.setText("sin");
    jButton21.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton21ActionPerformed(evt);
    }
    });

    jButton22.setText("tan");
    jButton22.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton22ActionPerformed(evt);
    }
    });

    jButton23.setText("Exit");
    jButton23.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton23ActionPerformed(evt);
    }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
    .addComponent(answer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
    .addComponent(jLabel1)
    .addComponent(jLabel2))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(jButton1)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
    .addComponent(jButton2))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jButton4)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
    .addComponent(jButton5))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jButton7)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(jButton8)
    .addComponent(jButton10))))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(jButton3)
    .addComponent(jButton6)
    .addComponent(jButton9))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 22, Short.MAX_VALUE)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addComponent(jButton11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jButton12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
    .addComponent(jButton14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jButton13, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jButton19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jButton18, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addComponent(jButton15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jButton22, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jButton21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jButton20, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)))
    .addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))))
    .addGap(21, 21, 21))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(answer, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton16)
    .addComponent(jButton20))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton18)
    .addComponent(jButton21))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(41, 41, 41)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton19)
    .addComponent(jButton15)))
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton17)
    .addComponent(jButton22))))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jButton11)
    .addGap(18, 18, 18)
    .addComponent(jButton12)
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(41, 41, 41)
    .addComponent(jButton14))
    .addComponent(jButton13)))))
    .addGroup(layout.createSequentialGroup()
    .addGap(66, 66, 66)
    .addComponent(jLabel1)
    .addGap(0, 0, 0)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton1)
    .addComponent(jButton2))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton4)
    .addComponent(jButton5))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jButton7)
    .addComponent(jButton8))
    .addGap(18, 18, 18)
    .addComponent(jButton10))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jButton3)
    .addGap(18, 18, 18)
    .addComponent(jButton6)
    .addGap(18, 18, 18)
    .addComponent(jButton9))
    .addComponent(jLabel2))))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 30, Short.MAX_VALUE)
    .addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap())
    );

    pack();
    }//

    private void jButton11ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    this.jLabel1.setText(this.answer.getText());
    this.answer.setText("");
    this.jLabel2.setText("+");
    }

    private void answerActionPerformed(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:
    this.answer.setText(this.answer.getText() + "1");
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.answer.setText(this.answer.getText() + "2");
    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here
    this.answer.setText(this.answer.getText() + "3");
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.answer.setText(this.answer.getText() + "4");
    }

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.answer.setText(this.answer.getText() + "5");
    }

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.answer.setText(this.answer.getText() + "6");
    }

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.answer.setText(this.answer.getText() + "7");
    }

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.answer.setText(this.answer.getText() + "8");
    }

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.answer.setText(this.answer.getText() + "9");
    }

    private void jButton10ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    this.answer.setText(this.answer.getText() + "0");
    }

    private void jButton12ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    this.jLabel1.setText(this.answer.getText());
    this.answer.setText("");
    this.jLabel2.setText("-");
    }

    private void jButton13ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    this.jLabel1.setText(this.answer.getText());
    this.answer.setText("");
    this.jLabel2.setText("*");
    }

    private void jButton14ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    this.jLabel1.setText(this.answer.getText());
    this.answer.setText("");
    this.jLabel2.setText("/");
    }

    private void jButton15ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    int n1 = 0, n2 = 0;
    double n3 = 0;
    n1 = Integer.parseInt(this.answer.getText());
    n2 = Integer.parseInt(this.jLabel1.getText());
    if ("+".equals(this.jLabel2.getText())) {
    n3 = n2 + n1;
    } else if ("-".equals(this.jLabel2.getText())) {
    n3 = n2 - n1;
    } else if ("*".equals(this.jLabel2.getText())) {
    n3 = n2 * n1;
    } else if ("/".equals(this.jLabel2.getText())) {
    n3 = n2 / n1;
    } else if ("^".equals(this.jLabel2.getText())) {
    n3 = Math.pow(n2, n1);
    }
    this.answer.setText("" + n3);
    }

    private void formWindowOpened(java.awt.event.WindowEvent evt) {
    // TODO add your handling code here:
    this.jLabel1.setVisible(false);
    this.jLabel2.setVisible(false);
    }

    private void jButton17ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    int n1 = 0, n2 = 0;
    n1 = Integer.parseInt(this.answer.getText());
    n2 = Math.abs(n1);
    this.answer.setText("" + n2);
    }

    private void jButton16ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    this.jLabel1.setText(this.answer.getText());
    this.answer.setText("");
    this.jLabel2.setText("^");
    }

    private void jButton18ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    int n1 = 0;
    double n2 = 0;
    n1 = Integer.parseInt(this.answer.getText());
    n2 = Math.log(n1);
    this.answer.setText("" + n2);
    }

    private void jButton19ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    double n1 = 0, n2 = 0;
    n1 = Integer.parseInt(this.answer.getText());
    n2 = Math.sqrt(n1);
    this.answer.setText("" + n2);
    }

    private void jButton20ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    double n1 = 0, n2 = 0;
    n1 = Integer.parseInt(this.answer.getText());
    n2 = Math.cos(n1);
    this.answer.setText("" + n2);
    }

    private void jButton21ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    double n1 = 0, n2 = 0;
    n1 = Integer.parseInt(this.answer.getText());
    n2 = Math.sin(n1);
    this.answer.setText("" + n2);
    }

    private void jButton22ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    double n1 = 0, n2 = 0;
    n1 = Integer.parseInt(this.answer.getText());
    n2 = Math.tan(n1);
    this.answer.setText("" + n2);
    }

    private void jButton23ActionPerformed(java.awt.event.ActionEven t evt) {
    // TODO add your handling code here:
    int result = JOptionPane.showConfirmDialog(null,"Are you sure ?",null,
    JOptionPane.YES_NO_OPTION);
    if(result==0)
    System.exit(0);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //
    /* 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.getClass Name());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {
    new myGUIform().setVisible(true);
    }
    });
    }
    // Variables declaration - do not modify
    private javax.swing.JTextField answer;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton18;
    private javax.swing.JButton jButton19;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton20;
    private javax.swing.JButton jButton21;
    private javax.swing.JButton jButton22;
    private javax.swing.JButton jButton23;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration
    }
    خروجی : (این برنامه نیاز به 23 تا باتن و دو لیبل و یک فیلد تکس دارد)

  28. #28
    کاربر تازه وارد
    تاریخ عضویت
    دی 1391
    محل زندگی
    تهران
    سن
    30
    پست
    44

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    کلاس dateرا براي تاريخ بسازيد و با استفاده از آن آرايه اي از اشياء از نوع تاريخ را از كاربر دريافت كرده و آنها را به
    صورت صعودي مرتب كرده و نمايش دهيد.

    import java.io.*;
    class Date
    {
    int d,m,y;
    void get()throws IOException
    {
    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("enter day:");
    d=Integer.parseInt(in.readLine());
    System.out.println("enter month:");
    m=Integer.parseInt(in.readLine());
    System.out.println("enter year:");
    y=Integer.parseInt(in.readLine());
    }


    void put() {
    System.out.println( y + "/" + m + "/" + d);
    }

    int compare(Date x) {

    if(y!=x.y)
    return y-x.y;
    if(m!=x.m)
    return m-x.m;
    return d-x.d;
    }
    }

    class Test1 {
    public static void main(String []args) throws IOException {

    int i,j,n=5;
    Date []a=new Date[n];
    Date t;
    for(i=0;i<n;i++)
    {
    a[i]=new Date();
    a[i].get();
    }

    for(i=0;i<n-1;i++)
    for(j=i+1;j<n;j++)
    if(a[i].compare(a[j])>0)
    {
    t=a[i];
    a[i]=a[j];
    a[j]=t;
    }

    for(i=0;i<n;i++)
    a[i].put();

    }
    }
    آخرین ویرایش به وسیله dasssnj : پنج شنبه 30 مرداد 1393 در 07:50 صبح

  29. #29
    کاربر تازه وارد
    تاریخ عضویت
    دی 1391
    محل زندگی
    تهران
    سن
    30
    پست
    44

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    برنامه اي بنويسيد كه مشخصات 5 دانشجو (نام ، شماره دانشجويي و تعداد دروس گذرانده شده و نمرات دروس) را
    دريافت و پس از گرفتن نمره ي هر درس ، معدل دانشجو را محاسبه و همراه با مشخصات وي چاپ كند. همچنين معدل
    ميانگين كل دانشجويان را محاسبه نماييد.

    import java.io.*;

    class Student {

    String name;
    int ID;
    int passed;
    float[] mark;

    float average()
    {
    float s=0;
    for(int i=0;i<passed;i++)
    s+=mark[i];
    return s/passed;
    }
    void get() throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    System.out.print("Enter Name: ");
    name = in.readLine();

    System.out.print("Enter ID: ");
    ID = Integer.parseInt(in.readLine());

    System.out.print("Enter Number of passed units :");
    passed = Integer.parseInt(in.readLine());

    mark = new float[passed];

    float sum = 0;
    for (int i = 0; i < passed; i++) {
    System.out.print("Mark[" + i + "] = ");
    mark[i] = Float.parseFloat(in.readLine());
    }
    }

    void put(boolean with_mark_) {
    System.out.println("****************************** **********");
    System.out.println("\t" + name + "\t|\t" + ID + "\t|\t" + passed + "\t\t|\t" + average());

    if (with_mark_) {
    System.out.println("****************************** **********");
    for (int i = 0; i < passed; i++) {
    System.out.print(mark[i]+"\t");
    }
    System.out.println();
    }
    }
    }

    class Test3 {

    public static void main(String[] args) throws IOException {
    int i,n=5;
    Student[] stu = new Student[n];

    for (i = 0; i < stu.length; i++) {
    stu[i] = new Student();
    stu[i].get();
    }

    float s=0;
    for (i = 0; i < stu.length; i++) {
    stu[i].put(true);
    s+=stu[i].average();
    }
    System.out.println("Average of all students: "+s/stu.length);
    }
    }
    آخرین ویرایش به وسیله dasssnj : پنج شنبه 30 مرداد 1393 در 08:10 صبح دلیل: لطفا کد ها را در تگ جاوا قرار دهید تا خوانا باشد

  30. #30
    کاربر تازه وارد
    تاریخ عضویت
    دی 1391
    محل زندگی
    تهران
    سن
    30
    پست
    44

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    کلاس Matrix را براي ماتريس بسازيد. در اين كلاس افزون بر بخش داده اي مناسب، مي بايست توابع دريافت، نمايش،
    مقداردهي، سازنده و همچنين توابع جمع، تفريق و ضرب ماتريسي نوشته شده باشد.

    class Matrix {

    double[][] deraye;

    public Matrix(double[][] newDeraye) {
    this.deraye = new double[newDeraye.length][newDeraye[0].length];
    for (int i = 0; i < this.deraye.length; i++) {
    for (int j = 0; j < this.deraye[0].length; j++) {
    this.deraye[i][j] = newDeraye[i][j];
    }
    }
    }

    public Matrix() {
    }

    public Matrix(int width, int height) {
    deraye = new double[width][height];
    }

    public double get(int i, int j)
    {
    if (i<this.deraye.length)
    if (j<this.deraye[0].length)
    return this.deraye[i][j];
    return 0;
    }

    public void set(int i, int j, double value)
    {
    if (i<this.deraye.length)
    if (j<this.deraye[0].length)
    this.deraye[i][j]=value;
    }

    public void get() throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Please Enter The width");
    int width = Integer.parseInt(reader.readLine());
    System.out.println("Please Enter The height");
    int height = Integer.parseInt(reader.readLine());

    deraye = new double[width][height];

    for (int i = 0; i < width; i++) {
    for (int j = 0; j < height; j++) {
    System.out.println("derayeye[" + (i + 1) + "][" + (j + 1) + "]");
    deraye[i][j] = Integer.parseInt(reader.readLine());
    }
    }
    }

    public void put() {
    System.out.println("Matix:");
    for (int i = 0; i < deraye.length; i++) {
    for (int j = 0; j < deraye[i].length; j++) {
    System.out.print(deraye[i][j] + "\t");
    }
    System.out.println("");
    }
    }

    public void set(double[][] newDeraye) {
    this.deraye = new double[newDeraye.length][newDeraye[0].length];
    for (int i = 0; i < this.deraye.length; i++) {
    for (int j = 0; j < this.deraye[0].length; j++) {
    this.deraye[i][j] = newDeraye[i][j];
    }
    }
    }

    public Matrix add(Matrix newMat) {
    if (this.deraye.length == newMat.deraye.length) {
    if (this.deraye[0].length == newMat.deraye[0].length) {
    Matrix RetMat = new Matrix(this.deraye.length, this.deraye[0].length);
    for (int i = 0; i < this.deraye.length; i++) {
    for (int j = 0; j < this.deraye[0].length; j++) {
    RetMat.deraye[i][j] = this.deraye[i][j] + newMat.deraye[i][j];
    }
    }
    return RetMat;
    }
    }
    return null;
    }

    public Matrix sub(Matrix newMat) {
    if (this.deraye.length == newMat.deraye.length) {
    if (this.deraye[0].length == newMat.deraye[0].length) {
    Matrix RetMat = new Matrix(this.deraye.length, this.deraye[0].length);
    for (int i = 0; i < this.deraye.length; i++) {
    for (int j = 0; j < this.deraye[0].length; j++) {
    RetMat.deraye[i][j] = this.deraye[i][j] - newMat.deraye[i][j];
    }
    }
    return RetMat;
    }
    }
    return null;
    }

    public Matrix mul(Matrix newMat)
    {
    if (this.deraye[0].length == newMat.deraye.length) {
    Matrix RetMat = new Matrix(this.deraye.length,newMat.deraye[0].length);
    for (int i= 0; i < deraye.length; i++) {
    for (int j = 0; j < newMat.deraye[0].length; j++) {
    double sum=0;
    for (int k = 0; k < deraye[0].length; k++) {
    sum+=this.deraye[i][k]*newMat.deraye[k][j];
    }
    RetMat.deraye[i][j]=sum;
    }
    }
    return RetMat;
    }
    return null;
    }
    }


    class Test2 {

    public static void main(String[] args) throws IOException {
    Matrix a= new Matrix();
    a.get();
    a.put();

    Matrix b = new Matrix();
    b.get();
    b.put();

    a.mul(b).put();
    }
    }
    آخرین ویرایش به وسیله dasssnj : پنج شنبه 30 مرداد 1393 در 07:50 صبح

  31. #31

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    خانم mahsa f تشکر از شما. فقط اگه میشه برنامه هاتونو که اینجا قرار میدید در تگ JAVA قرار بدید که به هم ریخته نباشن.
    موفق باشید

  32. #32
    کاربر تازه وارد
    تاریخ عضویت
    دی 1391
    محل زندگی
    تهران
    سن
    30
    پست
    44

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    كلاس عدد مختلط را همراه با توابع دريافت، نمايش، مقداردهي و جمع و تفريق و ضرب پياده سازي كنيد. سپس حاصل
    ضرب و جمع و تفريق دو عدد مختلط را محاسبه و چاپ كنيد.
    import java.io.*;

    class Complex {

    double x, y;

    void get() throws IOException {
    BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));

    System.out.print("Enter Real Part (X) : ");
    x = Double.parseDouble(breader.readLine());
    System.out.print("Enter Imagine Part (Y) : ");
    y = Double.parseDouble(breader.readLine());
    }

    void put() {
    System.out.println( x + "," + y );
    }

    void set(double X,double Y) {
    x=X;
    y=Y;
    }

    Complex add(Complex c) {
    Complex z=new Complex();
    z.x=x + c.x;
    z.y=y + c.y;
    return z;
    }

    Complex sub(Complex c) {
    Complex z=new Complex();
    z.x=x - c.x;
    z.y=y - c.y;
    return z;
    }

    Complex mul(Complex c) {
    Complex z=new Complex();
    z.x=x*y -c.x*c.y;
    z.y=y*c.x + x*c.y;
    return z;
    }
    }

    class Test4 {
    public static void main(String []a) throws IOException {

    Complex z1,z2,z3,z4;
    z1=new Complex();
    z2=new Complex();
    z1.set(2,3);
    z2.get();
    z3=z1.add(z2);
    z3.put();
    z4=z1.sub(z2);
    z4.put();
    z1.mul(z2).put();

    }
    }

  33. #33
    کاربر تازه وارد
    تاریخ عضویت
    دی 1391
    محل زندگی
    تهران
    سن
    30
    پست
    44

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    با تركيب كلاسهاي ماتريس و اعداد مختلط، كلاسcomplexMatرا بسازيد كه ماتريسي با درايه هاي مختلط است.
    از اين كلاس اشيائي ساخته و تواناييهاي آنرا بررسي كنيد.

    package HW3;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    /**
    *
    */
    public class ComplexMat {

    Complex[][] matrix;

    public ComplexMat() {
    }

    public ComplexMat(int n, int m) {
    this.matrix = new Complex[n][m];
    }

    public void Get() throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter number of rows : ");
    int n = Integer.parseInt(in.readLine());
    System.out.println("Enter number of columns : ");
    int m = Integer.parseInt(in.readLine());
    this.matrix = new Complex[n][m];
    for (int i = 0; i < this.matrix.length; i++) {
    for (int j = 0; j < this.matrix[0].length; j++) {
    this.matrix[i][j].get();
    }
    }
    }

    public void Put() throws IOException {

    for (int i = 0; i < this.matrix.length; i++) {
    for (int j = 0; j < this.matrix[0].length; j++) {
    this.matrix[i][j].put();
    System.out.print("\t");
    }
    System.out.print("\n");
    }
    }

    public ComplexMat Add(ComplexMat cmat) {
    if (cmat.matrix.length != this.matrix.length || cmat.matrix[0].length != this.matrix[0].length) {
    return null;
    }
    ComplexMat result = new ComplexMat(this.matrix.length, this.matrix[0].length);
    for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[i].length; j++) {
    result.matrix[i][j] = this.matrix[i][j].add(cmat.matrix[i][j]);
    }
    }
    return result;
    }

    public ComplexMat Mul(ComplexMat cmat) {
    int i = 0, j = 0, k = 0;
    ComplexMat result = null;
    if (this.matrix[0].length == cmat.matrix.length) {
    result = new ComplexMat(this.matrix.length, cmat.matrix[0].length);
    for (i = 0; i < this.matrix.length; i++) {
    for (j = 0; j < cmat.matrix[0].length; j++) {
    for (k = 0; k < this.matrix[0].length; k++) {
    result.matrix[i][j] = this.matrix[i][k].mul(cmat.matrix[k][j]);
    }
    }
    }
    } else {
    System.out.println("Invalid matrixes!");
    }
    return result;

    }
    }

    class Complex {

    double x, y;

    public Complex(double x, double y) {
    this.x = x;
    this.y = y;

    }

    void get() throws IOException {
    BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));

    System.out.print("Enter Real Part (X) : ");
    this.x = Double.parseDouble(breader.readLine());
    System.out.print("Enter Imagine Part (Y) : ");
    this.y = Double.parseDouble(breader.readLine());
    }

    void put() {
    System.out.println(x + " + " + y + "i");
    }

    Complex add(Complex c) {
    return new Complex(this.x + c.x, this.y + c.y);
    }

    Complex sub(Complex c) {
    return new Complex(this.x - c.x, this.y - c.y);
    }

    Complex mul(Complex c) {
    return new Complex(this.x * c.x - this.y * c.y,
    this.x * c.y + this.y * c.x);
    }
    }

  34. #34
    کاربر تازه وارد
    تاریخ عضویت
    دی 1391
    محل زندگی
    تهران
    سن
    30
    پست
    44

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    كلاس productرا براي نگهداري اطلاعات محصولات توليدي يك كارخانه بنويسيد كه در آن نام كالا، تاريخ توليد و
    تاريخ انقضا نگهداري شود. از اين كلاس اشيائي با نامها و تاريخهاي تصادفي ساخته و مشخص كنيد كه كداميك از آنها
    تاريخ مصرفشان گذشته و كدام را هنوز مي توان مصرف كرد.
    package HW3;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Calendar;
    import java.util.GregorianCalendar;

    /**
    *
    */
    public class Product {

    String name;
    Date prdDate;
    Date expDate;

    public Product() {
    }

    public Product(String name) {
    this.name = name;
    }

    public Product(String name, Date prdDate, Date expDate) {
    this.name = name;
    this.prdDate = prdDate;
    this.expDate = expDate;
    }

    public boolean IsExpired() {
    if (expDate.compareTo(Date.getToday()) == 1) {//
    return true;
    }
    return false;
    }

    void Put() {
    System.out.println("\nProductName:"+name);
    System.out.println(prdDate.toString());
    System.out.println(expDate.toString());
    }
    }

    class Date {

    static Date getToday() {
    Date today = new Date();
    Calendar cl = new GregorianCalendar();
    today.set(cl.get(Calendar.DAY_OF_MONTH), cl.get(Calendar.MONTH), cl.get(Calendar.YEAR));
    return today;
    }
    int d, m, y;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    //-----------------------------------------------------
    // This Part Gets The Day & Mounth & Year Of Our Date .
    //-----------------------------------------------------

    void get() throws IOException {
    System.out.print("Please Enter The Day ");
    String s = in.readLine();
    d = Integer.parseInt(s);
    while (d > 31 || d < 1) {
    System.out.println("ERROR !! ");
    System.out.println("Your Day Is Out Of Range , Please Enter Another Value ");
    s = in.readLine();
    d = Integer.parseInt(s);
    }
    System.out.print("Please Enter The Mounth ");
    s = in.readLine();
    m = Integer.parseInt(s);
    while (m > 12 || m < 1) {
    System.out.println("ERROR !! ");
    System.out.println("Your Mounth Is Out Of Range , Please Enter Another Value ");
    s = in.readLine();
    m = Integer.parseInt(s);
    }
    System.out.print("Please Enter The Year ");
    s = in.readLine();
    y = Integer.parseInt(s);
    while (y < 1370) {
    System.out.println("ERROR !! ");
    System.out.println("Your Year Is Out Of Range , Please Enter Another Value ");
    s = in.readLine();
    y = Integer.parseInt(s);
    }
    }

    @Override
    public String toString() {
    return y + "/" + m + "/" + d;
    }
    //----------------------------
    // This Part Print The Date !!
    //----------------------------


    void put() {
    System.out.println("Date: " + d + " - " + m + " - " + y);
    }
    //-------------------------------------------
    // This Part Compare 2 Date With Each Other .
    //-------------------------------------------

    int compareTo(Date b) {
    int x = 0;
    if (y < b.y) {
    x = 1;
    return x;
    }
    if (y > b.y) {
    x = 2;
    return x;
    }
    if (y == b.y) {
    if (m < b.m) {
    x = 1;
    return x;
    }
    if (m > b.m) {
    x = 2;
    return x;
    }
    if (m == b.m) {
    if (d < b.d) {
    x = 1;
    return x;
    }
    if (d > b.d) {
    x = 2;
    return x;
    }
    if (d == b.d) {
    x = 0;
    return x;
    }
    }

    }
    return x;
    }
    //--------------------------------------
    //This Part Set A Date With Your Value .
    //--------------------------------------

    void set(int D, int M, int Y) {
    d = D;
    m = M;
    y = Y;
    }

    void Date(int D, int M, int Y) {
    set(D, M, Y);
    }
    //-----------------------------
    //This Part Set Add Up 2 Date .
    //-----------------------------

    void add(Date A) {
    int i = 0, j = 0;
    d = A.d + d;
    while (d > 31) {
    d = d - 30;
    i++;
    }
    m = m + i;
    m = A.m + m;
    while (m > 12) {
    m = m - 12;
    j++;
    }
    y = y + j;
    y = A.y + y;
    }
    //---------------------------
    //This Part subtract 2 Date .
    //---------------------------

    void sub(Date B) {
    if (y > B.y) {
    if (d > B.d) {
    d = d - B.d;
    }
    if (d < B.d) {
    m--;
    d = d + 31;
    d = d - B.d;
    }
    if (m > B.m) {
    m = m - B.m;
    }
    if (m < B.m) {
    y--;
    m = m + 12;
    m = m - B.m;
    }
    }
    if (y < B.y) {
    if (B.d > d) {
    B.d = B.d - d;
    }
    if (B.d < d) {
    B.m--;
    B.d = B.d + 31;
    B.d = B.d - d;
    }
    if (B.m > m) {
    B.m = B.m - m;
    }
    if (B.m < m) {
    B.y--;
    B.m = B.m + 12;
    B.m = B.m - m;
    }
    }
    if (y == B.y) {
    if (m > B.m) {
    if (d > B.d) {
    d = d - B.d;
    }
    if (d < B.d) {
    m--;
    d = d + 31;
    d = d - B.d;
    }
    }
    if (m < B.m) {
    if (B.d > d) {
    B.d = B.d - d;
    }
    if (B.d < d) {
    B.m--;
    B.d = B.d + 31;
    B.d = B.d - d;
    }
    }
    if (m == B.m) {
    if (d > B.d) {
    d = d - B.d;
    }
    if (d < B.d) {
    B.d = B.d - d;
    }
    if (d == B.d) {
    d = 0;
    m = 0;
    y = 0;
    }
    }
    }
    }

    public static Date generateRandomDate() {
    Date newDate = new Date();
    newDate.d = (int) Math.random() * 30;
    newDate.m = (int) Math.random() * 12;
    newDate.y = (int) Math.random() * 5 + 1388;
    return newDate;
    }
    }

  35. #35
    کاربر تازه وارد
    تاریخ عضویت
    دی 1391
    محل زندگی
    تهران
    سن
    30
    پست
    44

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    سلام.مثل اینکه اصلا برنامه گذاشن و... هیچ فایده ای نداره!!!!!!!!!!!
    انگار به درد کسی نمیخوره....هیچ کس هم چیز جدیدی نمیذاره که حداقل دلمون خوش باشه!!!!!!!!!!!

  36. #36

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    متاسفانه همینطوریه.
    منم به همین دلیل دیگه برنامه نذاشتم.
    حتی جواب دادن به سوالاتم بی فایدس چون خیلی ها اداعای بزرگی دارن ولی جوابی به سوالات کسی نمیدن و وقتی کسی به سوالی جواب میده تازه میان تو صحنه و علیه جواب های داده شده جبهه میگیرن. در پاسخ به اینجور حرکتا بهترین کار اینه که جواب ادعا هاشونو نداد.
    و در پاسخ به بی اهمییت بودن برنامه هایی که در این تاپیک قرار داده میشه ، بهتر اینه که دیگه برنامه ای قرار ندیم.
    به هر حال من بازم از زحمتتون تشکر میکنم. امیدوارم که قدر زحماتتون دونسته بشه

  37. #37
    کاربر تازه وارد آواتار saeedfadaoddini
    تاریخ عضویت
    فروردین 1392
    محل زندگی
    کرمان
    سن
    36
    پست
    66

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا


  38. #38

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    این تاپیک میتونست یکی بهترین تاپیک ها بشه !! بهترین آموزش به نظرم دیدن کدهای دیگران هست به هر حال باعث تاسف هست که ادامه پیدا نکرد!امیدوارم دوستان حمایت کنند
    یه جمله ی کلیشه ای و صدالبته بسیار باارزش هست که میگه:
    ذکات علم در نشر آن است.

  39. #39
    کاربر تازه وارد
    تاریخ عضویت
    دی 1391
    محل زندگی
    تهران
    سن
    30
    پست
    44

    نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    سلام.
    دوستان چرا فقط دیگران رو تشویق میکنید؟!
    اگه خودتون دست به کار بشید و شرکت کنید و برنامه بذارید,دوباره رونق میگیره تایپیک.
    شماها شروع کنید,منم هستم...
    فقط شروع کنید!!!!!!!!!!!!!

  40. #40

    Post نقل قول: مجموعه برنامه‌های نوشته شده به زبان جاوا

    سلام
    این برنامه یه عکس رو باز می کنه ، تغییر سایز میده و تو یه فایل جدید ذخیره می کنه ...


    import java.awt.AlphaComposite;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.image.BufferedImage;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.JOptionPane;

    public class Resizer {
    private static final int IMG_WIDTH = 160;
    private static final int IMG_HEIGHT = 120;
    private static BufferedImage resizeImage(BufferedImage originalImage, int type){
    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();

    return resizedImage;
    }

    private static BufferedImage resizeImageWithHint(BufferedImage originalImage, int type){

    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();
    g.setComposite(AlphaComposite.Src);

    g.setRenderingHint(RenderingHints.KEY_INTERPOLATIO N,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING,
    RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING ,
    RenderingHints.VALUE_ANTIALIAS_ON);

    return resizedImage;
    }
    public static void resize(String ico,String folder) {
    try{

    BufferedImage originalImage = ImageIO.read(new File(ico));
    int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();

    //BufferedImage resizeImageJpg = resizeImage(originalImage, type);
    //ImageIO.write(resizeImageJpg, "jpg", new File(folder));

    //BufferedImage resizeImagePng = resizeImage(originalImage, type);
    //ImageIO.write(resizeImagePng, "png", new File(folder));

    BufferedImage resizeImageHintJpg = resizeImageWithHint(originalImage, type);
    ImageIO.write(resizeImageHintJpg, "jpg", new File(folder));

    BufferedImage resizeImageHintPng = resizeImageWithHint(originalImage, type);
    ImageIO.write(resizeImageHintPng, "png", new File(folder));

    }catch(IOException e){
    System.out.println(e.getMessage());
    }
    }

    }

صفحه 1 از 3 123 آخرآخر

تاپیک های مشابه

  1. مجموعه برنامه های نوشته شده به زبان C و ++C
    نوشته شده توسط Nima_NF در بخش برنامه نویسی با زبان C و ++C
    پاسخ: 319
    آخرین پست: جمعه 11 اسفند 1396, 14:11 عصر
  2. مبتدی: برای اجرای برنامه های نوشته شده به زبان جاوا با استفاده از notpad++ چه باید کرد؟
    نوشته شده توسط helia64 در بخش برنامه‌نویسی جاوا
    پاسخ: 2
    آخرین پست: سه شنبه 19 شهریور 1392, 15:33 عصر
  3. آموزش: مجموعه برنامه‌های نوشته شده به زبان جاوا
    نوشته شده توسط m.a.d1992 در بخش Java SE : نگارش استاندارد جاوا
    پاسخ: 0
    آخرین پست: یک شنبه 02 تیر 1392, 18:56 عصر
  4. گفتگو: efficiency - بازدهی زمان اجرا در برنامه های نوشته شده به زبان جاوا + یک مثال
    نوشته شده توسط jlover در بخش برنامه‌نویسی جاوا
    پاسخ: 10
    آخرین پست: شنبه 22 خرداد 1389, 09:57 صبح
  5. اتصال ترازوی دیجیتال به برنامه های نوشته شده به زبان دلفی
    نوشته شده توسط DlphIran در بخش برنامه نویسی در Delphi
    پاسخ: 4
    آخرین پست: شنبه 06 خرداد 1385, 07:30 صبح

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •