如果用户在输入输入后单击“否”,我将尝试让我的代码循环。
import java.awt.event.WindowAdapter;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Sizer extends WindowAdapter
{
public static void main (String[]args){
JFrame m = new JFrame();
JOptionPane.showMessageDialog(m,"Ok To set the window size you are going to type in the number for each value REMEMBER THE SIZE IS IN PIXELS");
String input1= JOptionPane.showInputDialog("Height (suggested under 1080 and above 300)");
int Height= Integer.parseInt( input1);
在此输入之后,我必须确认该用户是否正确输入了它,如果他们单击“是”,它会继续运行,如果他们单击“否”,它会退出我希望它让用户再次输入它,我该怎么做?
int a1 = JOptionPane.showConfirmDialog(m,"Are you sure that this is the correct Height"+ Height);
if (a1==JOptionPane.YES_OPTION){
if (a1==JOptionPane.NO_OPTION){
}
String input2= JOptionPane.showInputDialog("Width (suggested under 1920 and above 300)");
int Width = Integer.parseInt( input2);
JFrame frame = new JFrame();
Slop comp = new Slop();
frame.add(comp);
frame.setSize(Height,Width);
frame.setTitle("Slop of a Line");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
}
相关分类