Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

Netbean要怎麼用阿???(20點相贈)

最近終於收到通知選到了物件導向程式設計

老師是用Netbean來寫JAVA程式

但我前幾堂都沒去不知道Netbean要怎麼操作>"<

軟體我是灌好了

然後老師出了以下這組程式...

// Java extension packages

import javax.swing.JOptionPane; // import class JOptionPane

public class InputDialog {

// main method begins execution of Java application

public static void main( String args[] )

{

String firstNumber; // first string entered by user

String secondNumber; // second string entered by user

int number1; // first number to add

int number2; // second number to add

int sum; // sum of number1 and number2

// read in first number from user as a string

firstNumber =

JOptionPane.showInputDialog( "Enter first integer" );

// read in second number from user as a string

secondNumber =

JOptionPane.showInputDialog( "Enter second integer" );

// convert numbers from type String to type int

number1 = Integer.parseInt( firstNumber );

number2 = Integer.parseInt( secondNumber );

// add the numbers

sum = number1 + number2;

// display the results

JOptionPane.showMessageDialog(

null, "The sum is " + sum, "Results",

JOptionPane.PLAIN_MESSAGE );

System.exit( 0 ); // terminate application

} // end method main

}

要我們作修改 改成程式run出來會有一個方塊

把三個數值填進去就能判斷這三個數值是否能組成三角形

如果可以那是正 . 直角還是等腰三角形......

我只知道一開始先按New project

然後把InputDialog打入project name

其他我完全不曉得怎麼做....

拜託哪位大大教教我

感激不盡~~~~~~~~~~~~~~~~~~~~~

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    請到我做的教學網頁,內有圖片詳解:

    http://www.cs.ccu.edu.tw/~hwp94/goodboy/aaa.htm

    下面是完整程式碼,可以複製貼上:

    /*

    * Main.java

    *

    * Created on 2005年10月3日, 下午 8:50

    *

    * To change this template, choose Tools | Options and locate the template under

    * the Source Creation and Management node. Right-click the template and choose

    * Open. You can then make changes to the template in the Source Editor.

    */

    package javaapplication1;

    /**

    *

    * @author Eric

    */

    // Java extension packages

    import javax.swing.JOptionPane; // import class JOptionPane

    public class Main {

    // main method begins execution of Java application

    public static void main( String args[] )

    {

    String firstNumber; // first string entered by user

    String secondNumber; // second string entered by user

    String thirdNumber;//third string entered by user

    int number1; // first number

    int number2; // second number

    int number3;//third number

    // read in first number from user as a string

    firstNumber =

    JOptionPane.showInputDialog( "請輸入第一個邊長" );

    // read in second number from user as a string

    secondNumber =

    JOptionPane.showInputDialog( "請輸入第二個邊長" );

    //read in third number from user as a string

    thirdNumber =

    JOptionPane.showInputDialog( "請輸入第三個邊長" );

    // convert numbers from type String to type int

    number1 = Integer.parseInt( firstNumber );

    number2 = Integer.parseInt( secondNumber );

    number3 = Integer.parseInt( thirdNumber );

    if(number1 == number2 && number2 == number3)

    JOptionPane.showMessageDialog(

    null, "這是一個正三角形", "Results",

    JOptionPane.PLAIN_MESSAGE );

    if(number1 == number2 || number2 == number3 || number1 == number3)

    JOptionPane.showMessageDialog(

    null, "這是一個等腰三角形", "Results",

    JOptionPane.PLAIN_MESSAGE );

    number1 = number1*number1;

    number2 = number2*number2;

    number3 = number3*number3;

    if(number1 == number2+number3 || number2 == number3+number1 || number3 == number2+number1)

    JOptionPane.showMessageDialog(

    null, "這是一個直角三角形", "Results",

    JOptionPane.PLAIN_MESSAGE );

    System.exit( 0 ); // terminate application

    } // end method main

    }

Still have questions? Get your answers by asking now.