ok i've spent a while trying to find a solution for this i even checked the post:
but i still can't figure out how to do what i want my problem is the following: when i go to check if the value is in the given range it only checks the first value for example 32 and ignore the rest here is the code. Please help don't just take me to a different post i'm new with java i'll really appreciate your help
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.MessageBox;
public class Disneyland {
protected Shell shell;
private Text textHeight;
private String height;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
Disneyland window = new Disneyland();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setImage(SWTResourceManager.getImage(Disneyland.class, "/Images/1000px-Disneyland_Park_Logo.svg.png"));
shell.setSize(600, 400);
shell.setText("Disneyland Park Height Requirements");
Label lblNewLabel = new Label(shell, SWT.NONE);
lblNewLabel.setImage(SWTResourceManager.getImage(Disneyland.class, "/Images/disney_magin_disneyland_6899.png"));
lblNewLabel.setBounds(233, 10, 128, 134);
Label lblNewLabel_1 = new Label(shell, SWT.NONE);
lblNewLabel_1.setForeground(SWTResourceManager.getColor(0, 51, 255));
lblNewLabel_1.setFont(SWTResourceManager.getFont("MathJax_Fraktur", 18, SWT.NORMAL));
lblNewLabel_1.setBounds(125, 166, 349, 27);
lblNewLabel_1.setText("Please input your height in inches\n");
textHeight = new Text(shell, SWT.BORDER);
textHeight.setBounds(233, 213, 128, 27);
Button btnSubmit = new Button(shell, SWT.NONE);
btnSubmit.setForeground(SWTResourceManager.getColor(SWT.COLOR_TRANSPARENT));
btnSubmit.setImage(SWTResourceManager.getImage(Disneyland.class, "/Images/disney.gif"));
btnSubmit.setBounds(274, 261, 56, 45);
btnSubmit.addListener(SWT.Selection, new submitButtonListener());
}
public class submitButtonListener implements Listener {
public void handleEvent(Event event) {
height = textHeight.getText();
if(Integer.parseInt(height)<32 ){
MessageBox messagebox = new MessageBox(shell, SWT.OK );
messagebox.setText("Height limitations");
messagebox.setMessage("For your own safety you are only allowed to use the rides with Any Height signs under adult supervision. We hope you grow up very quick :)");
messagebox.open();
}
if(Integer.parseInt(height)==32 && Integer.parseInt(height)<35 ){
MessageBox messagebox = new MessageBox(shell, SWT.OK );
messagebox.setText("Height limitations");
messagebox.setMessage("You are allowed to go on the Autopia accompanied by another rider 54 inches or taller");
messagebox.open();
}
if(Integer.parseInt(height)== 35 && Integer.parseInt(height) < 40 ){
MessageBox messagebox = new MessageBox(shell, SWT.OK );
messagebox.setText("Height limitations");
messagebox.setMessage("You are allowed to go on the Autopia and the Gadget's Go Coaster accompanied by another rider 54 inches or taller");
messagebox.open();
}
if(Integer.parseInt(height)== 40 && Integer.parseInt(height)<42 ){
MessageBox messagebox = new MessageBox(shell, SWT.OK );
messagebox.setText("Height limitations");
messagebox.setMessage("You are allowed to go on the Autopia, Gadget's Go Coaster, the Big Thunder Mountain Railroad, Space Mountain, Splash Mountain and Star Tours accompanied by another rider 54 inches or taller");
messagebox.open();
}
if(Integer.parseInt(height)== 42 && Integer.parseInt(height)<46 ){
MessageBox messagebox = new MessageBox(shell, SWT.OK );
messagebox.setText("Height limitations");
messagebox.setMessage("You are allowed to go on the Autopia, Gadget's Go Coaster, the Big Thunder Mountain Railroad, Space Mountain, Splash Mountain, Star Tours and Matterhorn Bobsleds accompanied by another rider 54 inches or taller");
messagebox.open();
}
if(Integer.parseInt(height)== 46 && Integer.parseInt(height) < 54 ){
MessageBox messagebox = new MessageBox(shell, SWT.OK );
messagebox.setText("Height limitations");
messagebox.setMessage("You are allowed to go on the Autopia, Gadget's Go Coaster, the Big Thunder Mountain Railroad, Space Mountain, Splash Mountain, Star Tours, Matterhorn Bobsleds and Indiana Jones Adventure accompanied by another rider 54 inches or taller");
messagebox.open();
}
if(Integer.parseInt(height)>= 54 ){
MessageBox messagebox = new MessageBox(shell, SWT.OK );
messagebox.setText("Height limitations");
messagebox.setMessage("You are allowed to go on the Autopia without adult supervision" );
messagebox.open();
}
}
}
// TODO Auto-generated method stub
}
Aucun commentaire:
Enregistrer un commentaire