JOptionePane
에서 이중 입력을 사용하여 사각형 영역을 계산합니다. 그래서 나는 사용자에게 length
을 넣고 width
을 입력해야합니다. 그러나, 첫 번째 입력 후, 난 바로 뒤에 폭을 doesft 팝업에 대한 두 번째 JOptionPane
리더를 넣어. 나는 이것이 많은 일을 필요로한다는 것을 깨닫는다. 그는 콘솔에서 입력을 기다리고 있기 때문에JOptionPane이 독자를 따라 간다
String inputLength = JOptionPane.showInputDialog("Enter the length of the edge: ");
int length = Integer.parseInt(inputLength);
가 Scanner
을 제거
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Project3_1 {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int length;
int width;
int surfacearea;
JOptionPane.showInputDialog("Enter the length of the edge: ");
length = reader.nextInt(); // doesnt work past this
JOptionPane.showInputDialog("Enter the width of the edge: ");
width = reader.nextInt();
surfacearea = length * width;
JFrame someFrame = new JFrame(); // how to insert surfacearea??
JLabel label = new JLabel();
someFrame.add(label);
someFrame.setSize(230, 230);
someFrame.setVisible(true);
}
}
귀하의 질문은 무엇인가? 또는 무엇을 원하니? –
@Yohannes 질문은 두 번째 입력을하지 않는 이유입니다. – minigeek
아래의 minigeek의 답변을 참조하십시오. 또한 "표면적 삽입"이란 무엇을 의미합니까? –