Redirecting based ons creen width
Hi,
I've a problem with a java applet. I now have the following:
import java.applet.*;
import java.awt.*;
import java.net.*;
public class ScreenRes extends java.applet.Applet {
public void start() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
String file = null;
URL url = null;
switch(screenSize.width) {
case 640: file = "pc/index.htm"; // 640x480
break;
case 800: file = "pc/index.htm"; // 800x600
break;
case 1024: file = "pc/index.htm"; // 1024x768
break;
case 1280: file = "pc/index.htm"; // 1280x1024
break;
case 1400: file = "pc/index.htm"; // 1400x1150
break;
case 1600: file = "pc/index.htm"; // 1600x1200
break;
default: file = "phone/index.htm";
break;
}
try { url = new URL(getDocumentBase(), file); }
catch ( MalformedURLException e) {
url = null;
}
if (url != null) {
getAppletContext().showDocument(url);
}
}
}
But what I need is that when the screen width is smaller than 640 then go to phone/index.htm and when the width is equal or bigger than 640 then go to pc/index.htm
Could somebody change the code for me?
Thanks in advance!
Frank
Maybe I'm missing something but it sounds like you could replace that whole switch with:
String file = (screenSize.width >= 640) ? "pc/index.htm" : "phone/index.htm";
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks