小编atd*_*511的帖子

如何组合GUI类和扫描仪类?

我是java的新手,我正在尝试创建一个程序,首先要求用户输入一些数字,然后输出一个卷,区域等等.另外我想显示一个矩形,我不知道怎么做,因为我的程序运行正常,它不会显示矩形.我能做什么?

package testchap3;

import java.util.*;
import javax.swing.JApplet;
import java.awt.*;

public class Chapter_3 extends JApplet
{
    public void paint(Graphics page)
    {
        page.drawRect(50,50,60,60);
    }

    public static void main(String[] args)
    {
        int lenght,width,height,volume,Area,Perimeter;

        Scanner scan = new Scanner(System.in);

        System.out.println("What is the lenght:");
        lenght = scan.nextInt();

        System.out.println("What is the height:");
        height = scan.nextInt();

        System.out.println("What is the width:");
        width= scan.nextInt();

        volume = (lenght*height*width);
        Area= volume/height;
        Perimeter= lenght+width+lenght+width;   

        System.out.println("Your volume is:"+volume);
        System.out.println("Your Area is:"+ Area);
        System.out.println("Your perimeter is:"+Perimeter);

     }
}
Run Code Online (Sandbox Code Playgroud)

java swing java.util.scanner

0
推荐指数
1
解决办法
600
查看次数

标签 统计

java ×1

java.util.scanner ×1

swing ×1