Opening a jsp from an applet in a frame?

this is the code i'm using to open a new jsp and send some stuff in the header. it works fine but it does not support the frameset i am using... any ideas how i can open this page in the frame?
thanks
URL url = getCodeBase();
try{
getAppletContext().showDocument (new URL (url+"AcceptHousePos.jsphouse="+myHouse.getString()));
catch(MalformedURLException e) {
showStatus("URL not found");

Do you want to open a jsp application in a frame when you click on the applet?If so, there is a programme in http://www.globalleafs.com -Java-Java Applets 's download section. Check it out.

Similar Messages

  • Opening a browser from an applet

    I got a problem, I want to open a browser from my applet, but I just found one way:
    getAppletContext().showDocument(new URL(
    "http://www.java.sun.com"), "_blank");
    but the problem is: with this, the default browser with defaul settings is opened, and that's what I don't want...
    how can I open the browser with some settings (for example size, or no-url-bar, etc)
    thx for help

    hi,
    try this code:
    public void showDocument(java.net.URL url, String targetWindow)
    when targetWindow can be:
    "_blank" Display the document in a new, nameless window.
    "windowName" Display the document in a window named windowName. This window is created if necessary.
    "_self" Display the document in the window and frame that contain the applet.
    "_parent" Display the document in the applet's window but in the parent frame of the applet's frame. If the applet frame has no parent frame, this acts the same as "_self".
    "_top" Display the document in the applet's window but in the top-level frame. If the applet's frame is the top-level frame, this acts the same as "_self".

  • Opening a socket from an applet

    I tried to open a socket from an applet to a server on a remote computer and I've got a refusal message.
    When I try it on a server in the local machine, it works.
    What could be the problem ?
    P.S. : when I open the socket from an application in the Java environment, to the same remote server it works ok.

    this is part of the security system built into java and Applets
    unless you sign an Applet it cannot do many "dangerous" things, like..
    access the loacl file system
    connect to any server except the server that it came from

  • Open a JSP from an ScreenFlow in a new window

    Hi all, a have a proccess in wich I get user input with a Screen Flow. The ScreenFlow has some JSP to collect user data (User Information, Economical data, Provider, ....). Some of the fields in the JSP needs to be filled with information that is in a database. For example, the is a field "Provider" that needs to be search in a database. I want to open a JSP in a new window in order to show a list of provider (or whatever other data I need). This JSP in a new window would return the data in a specific field.
    Now, I have done this modelling in the ScreenFlow but if the JSP form has lot of field of that kind the proccess get very complex.
    There is any way to open a JSP in a new Window (from a presentation of a ScreenFlow) without loosing the JSP context? (i mean having the ability to access BPM methods and data).
    Thanks in advance.

    Do you want to open a jsp application in a frame when you click on the applet?If so, there is a programme in http://www.globalleafs.com -Java-Java Applets 's download section. Check it out.

  • Post parameters to a JSP from an applet

    Hello,
    Is there a way to send a post request to a JSP page from an applet ? Here is the scenario I am looking for :
    In Test.jsp, I invoke an applet. The applet should then do a POST request to the JSP. Currently, I am able to send a JSP request by appending parameters to the query string as
    getAppletContext().showDocument(new URL(getDocumentBase(),"Test.jsp?querystring")); in the applet. But this will be showing the parameters in the URL. I would like to have the parameters sent as "POST". I tried doing something like
    String data = "All URL encoded parameter names and values";
    URL postURL = new URL("Test.jsp");
    conn = (HttpURLConnection)postURL.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(data);
    wr.flush();
    wr.close();
    But how do I pass the control back to the JSP ? Any thoughts ?

    Thanks for all your responses. I posted the request and still couldn't get it working. Here is my code
    osDetection.jsp:
    <%@ page contentType="text/html; charset=UTF-8" %>
    <% // Get all the request parameters
    String userOSVersion = request.getParameter("osVersion") == null ? "" : request.getParameter("osVersion");
    String detect = request.getParameter("detect") == null ? "" : request.getParameter("detect");
    %>
    <% if(detect.equals("")) { %>
              <span>detect os version</span>
    <% } %>
    <%     if("os".equals(detect)) { %>
    <div align="center">
    <object width="250" height="75">
    <param name="type" value="application/x-java-applet" />
    <param name="code" value="Detection.class" />     
    <comment>
    <embed type="application/x-java-applet" code="Detection.class" width="1" height="2" />
    <noembed>No OS detected</noembed>
    </comment>
    </object>
    </div>     
    <% } %>
    OS Version: <%=userOSVersion%>
    Detect:          <%=detect%>
    Detection.java
    import java.applet.*;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLEncoder;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    public class Detection extends Applet {
         public void init() {
              HttpURLConnection conn = null;
              try {
                   String data = "osVersion=" + URLEncoder.encode(System.getProperty("os.version"),"UTF-8");
                   URL postURL = new URL("http://localhost:8080/detection/osDetection.jsp");
                   System.out.println("posting to the url :");
                   conn = (HttpURLConnection)postURL.openConnection();
                   conn.setRequestMethod("POST");
                   conn.setDoOutput(true);
                   System.out.println("connection open");
                   OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                   wr.write(data);
                   wr.flush();
                   wr.close();
                   // Get the response code
                   int code = conn.getResponseCode();
                   System.out.println("Response code of the object is "+code);
                   if (code==200) {
                   System.out.println("OK");
                   // Get the response
                   BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                   String line;
                   while ((line = rd.readLine()) != null) {
                   System.out.println(line);
                   rd.close();
                   conn.disconnect();
              } catch(Exception ex) {
                   System.out.println("Error:" + ex.getMessage());
    Am I missing something here ? I see the response being written to the Java console but how do I transfer the control back to JSP to do further processing in the JSP ?
    Thanks much in advance.

  • Opening a jsp from another server(Weblogic) from webdynpro running on WAS

    hi,
      I have an application deployed on weblogic and want that when i click on a link in webdynpro it should open my jsp page in a new window and i should be able to send some values to it also.
      there is one way i know of, that is like this:-
    IWDWindow newwindow = wdComponentAPI.getWindowManager().createExternalWindow("https://.../login?userid="userid"&pass="+pass,"header",false);
    newwindow.open();
    but in this case we are sending the parameters from URL like login id and password. I donot want to do that as the user can see this info on the browser. Is there any way in which i can send this user id and password to a jsp page/servlet without "url?..."
    thanks
    I mean i want it to act as a form submit or something like in servlets and jsp's

    Hi Venkat:
       There are couple of ways to achieve this:
    One of them are Pamita's approach, get details from her that how did she fixed the UserID\PassWd.
    The other best approach is use the AppIntegrator for the same, you can call any other web-applications into your own application. For AppIntg we create a system, where we can specify the UserID\PassWds too which is transparent to user.
    Hope this helps you.
    Thanks,
    Munna SAP.

  • Opening 1 jsp from another

    Hi,
    I am opening one jsp on click of a button of another.
    Button's even code is here:
    InputField txt = (InputField) this.getComponentByName("InputName");
         IPortalComponentRequest req = (IPortalComponentRequest) this.getRequest();
         IPortalComponentResponse res = (IPortalComponentResponse) this.getResponse();
    req.getComponentSession().putValue("openurl", "Yes");
    Based on This value "Yes", another JSP is opened via this...
    <%
    try     {
         com.sapportals.portal.prt.component.IPortalComponentRequest componentRequest;
         String open = componentRequest.getComponentSession().getValue("openurl").toString();
         if(open.equals("Yes"))     {
    %>
          <SCRIPT language="JavaScript">            
                    EPCM.doNavigate("pcd:portal_content/Dev/EP1/testAPC");
          </SCRIPT>
    <% }
    catch(Exception ex)     { %>
    <%= "Test" %>
    <%
    %>
    But i am getting exception...
    Can you plz guide me in this?
    Regards,
    Dev

    Hi,
    Can you specify the exception you get,
    in any case the url used in EPCM.doNavigate() has the following format and your url specification is not right.
    "ROLES://portal_content/folder1/role1/workset1/iView111"
    In other words the pcd: is replaced with ROLES://
    Please refer to the links below,
    Navigation Target
    http://help.sap.com/saphelp_nw04s/helpdata/en/18/3fb84033a8b533e10000000a155106/frameset.htm
    For information on EPCM.doNavigate()
    http://help.sap.com/saphelp_nw04s/helpdata/en/26/71c74030308431e10000000a1550b0/frameset.htm
    Further more
    <i><b>com.sapportals.portal.prt.component.IPortalComponentRequest componentRequest;
         String open = componentRequest.getComponentSession().getValue("openurl").toString();</b></i>
    This part of the code is not usually done.
    What you have done is actually put a bean in the component session of type java.lang.String
    Use the following declaration,
    <jsp:useBean id="openurl" scope="session" class="java.lang.String"
    />
    Check up the link for the reference,
    http://help.sap.com/saphelp_nw04s/helpdata/en/f9/1b0f4186b5d349e10000000a1550b0/frameset.htm
    This declaration will done above all your form elements
    In your page you can direcly use "openurl" as a variable.
    For example
    <%
    if(openurl != null)
    if(openurl.equals("yes"))
    //Write some code
    %>
    Regards,
    Harish
    (Please award points for helpful answers)
    Message was edited by: HARISH SUBRAMANIAN
    Message was edited by: HARISH SUBRAMANIAN

  • Open web pages from an applet

    I'm developing an applet that has to open some web pages.
    The only way I know is to use the method showDocument that
    needs and URL. So, how to pass parameters to the web page?
    I don't want to put them in the URL: everyone can see
    "secret data"!
    Help me, please.

    Take a look at this example that uses a JEditor pane to hold the HTML page.
    //Create a new JEditor Pane
    jep = new JEditorPane( );
    //Ensure the pane is not editable
    jep.setEditable(false);  
    //Use this to get local HTML file
    URL fileURL = this.getClass().getResource("Manual/Manual.htm");
    //add the html page to the JEditorPane
    jep.setPage(fileURL);Ok the core line of code here is this.
    URL fileURL = this.getClass().getResource("Manual/Manual.htm");The standard method for accessing a html file via a URL is thus. As you can see its very similar.
    URL fileURL = new URL("http://www.comp.glam.ac.uk/pages/staff/asscott/progranimate/docs/Manual/Manual.htm");this.getClass().getResourse() will return the file location of the class you are working with.
    By doing the following you can access manual.html in a folder called Manual that sits in the same file location as the class file you are using.
    URL fileURL = this.getClass().getResource("Manual/Manual.htm");I hope this helps.
    Andrew.

  • Open a JFrame from an applet

    I have an applet in which I have a JButton.
    When you click the button, I want a new window to open with a JFrame. Is that possile?
    I've written as follow but nothing happens when I click the button.
    1. In the applet, I've written:
    public class MyApplet extends Applet {
    if (e.getActionCommand() == myButton) {
    frame.getContentPane().add(new Blabla(), BorderLayout.CENTER);
    2. In the frame, I've written:
    public class Blabla extends JFrame {

    Thanks.
    Now a new window is opened when I click the button, but it's empty....
    In the frame I have a container, is that a problem? I don't know where to put "your":
    "getContentPane().setLayout(new BorderLayout());"
    I've written:
    public class Blabla extends JFrame {
    boolean inAnApplet = true;
    private boolean laidOut = false;
    private JButton b1, b2, b3;
    private JLabel fnamn;
    public Blabla() {
    Container contentPane = getContentPane();
    contentPane.setLayout(null);
    b1 = new JButton("some text");
    contentPane.add(b1);

  • How do I open a url from an applet?

    is it done the same way with HTTPUrlConnection as with an application or is it done in a different way? I'm getting a "ClassCastException"

    Now I'm trying to call a CGI script and past things in through the post method... I still get a ClassCastException. This exact same code worked in the applet, once again. here is the code I am using:
                   URL url = new URL ("http://address.pl");
                   HttpURLConnection cxn = (HttpURLConnection) url.openConnection();
                   cxn.setRequestMethod("POST");;
                   cxn.setUseCaches(false);
                   cxn.setDoOutput(true);
                   cxn.setDoInput(true);
                   ByteArrayOutputStream bytes = new ByteArrayOutputStream(400);
                   PrintWriter writer = new PrintWriter (bytes,true);
                   writer.print("hello=world&food=good");
                   writer.flush();
                   cxn.setRequestProperty("Content-Length",String.valueOf(bytes.size()));
                   cxn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
                   bytes.writeTo(cxn.getOutputStream());

  • [NEWBIE] How to open a frame from an Applet?

    Hi, I'm trying to open a JFrame from an Applet. Basically, I would like that, once the user selects an option from a JMenu, a Frame would be shown with a text box where user could type some content.
    I built both the Applet and the Frame, and singularly they work. When I execute the main method from the JFrame, the window appears, but when I execute something like the following from the applet:
    MyFrame mf = new MyFrame();
    mf.setVisible(true);nothing is shown. I'm sure that I don't know something, but I just started with applets.
    Thanks for any help,
    Marco

    If MyFrame is a subclass of JFrame, then it should not
    make any difference.
    What do you need the JFrame for? Can this be done
    using another "screen" by using a CardLayout?From a menu, when the user selects 'Start game' I need a text box coming out so that the user can insert a word. This word should then evaluate an instance member of the Applet.
    Marco

  • Opening frames from an applet

    Me and a friend are making an applet, and would like it to open a new frame at some point.
    It works perfectly* on his WIN 2k IE 5.0 but somehow it does not on my WIN 2k IE 6.0
    Is it no longer legal to open new windows from an applet?
    Thanks.
    *Except for the warning. Btw, is that warning removable?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    If the window doesnt show up, you might have an exception thrown somewhere. I assume you are using a Java Plug-In since you are using IE6.0. You can bring up the java console, if you open the Java Plug-In icon in the Control Panel and enable "Show Java Console". Restart your browser and try again and see if you are getting a stacktrace in the java console.You can also see what version of java you are using in the control panel, or change it in the Java Plug-In options (Advanced tab) if you have more than one installation installed.

  • Converting an applet into a frame

    hello.
    this is james mcfadden. I am developing a 2-player BlackJack card game in java. how do i convert the following 2 pieces of code from an applet into a frame?
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class Blackjack extends Applet implements ActionListener,Runnable{
         private Deck deck;     //The deck...
         private Hand player_hand;//player hand
         private Hand dealer_hand;//dealer hand.
         private Button bHit=new Button("Hit");
         private Button bStay=new Button("Stay");
         private Button bRestart=new Button("New Game");
         //lets do some double buffering.
         Image offIm=null;
         Graphics offGraphics=null;
         Dimension offDimension=null;
         Image[] card_images = new Image[52];
         private boolean cards_loaded = false;
         private int current_card_loading = 0;
         String message;                         //print a message...
         int width;          //The width of the applet
         int height;          //The height of the applet
         int card_width = -1;
         int card_padding = -1;     //How much should we pad the cards by..?
         private int games=-1;     //How many games have been played?
         public void init() {
              Thread card_loader = new Thread(this);
              card_loader.start();
         public void newGame(){
              bHit.setEnabled(true);
              bStay.setEnabled(false);
              player_hand = new Hand();     //Create new hands...
              dealer_hand = new Hand();
              //shuffle the deck.
              deck.shuffleCards();
              games++;
         public void hit(){
              bStay.setEnabled(true);
              player_hand.addCard(deck.dealCard());
              if(player_hand.getValue() > 21){
                   message = "You loose! (score:"+player_hand.getValue()+")";
                   //disable the hit and stay buttons...
                   bHit.setEnabled(false);
                   bStay.setEnabled(false);
                   return;
              message = "Score: "+player_hand.getValue();     
         public void stay(){
              while(dealer_hand.getValue() < 17){
                   dealer_hand.addCard(deck.dealCard());
              if(dealer_hand.getValue() <= 21 && player_hand.getValue() < dealer_hand.getValue())
                   message = "You loose! (" + player_hand.getValue()+
                             " - "+dealer_hand.getValue()+")";
              }else if (player_hand.getValue() == dealer_hand.getValue())
                   message = "You draw! (" + player_hand.getValue()+")";
              }else {
                   message = "You win! (" + player_hand.getValue()+
                             " - "+dealer_hand.getValue()+")";
              bHit.setEnabled(false);
              bStay.setEnabled(false);
         public void actionPerformed(ActionEvent e) {
              if(e.getSource() == bRestart)
                   newGame();
              }else if (e.getSource() == bHit)
                   hit();
              }else if (e.getSource() == bStay)
                   stay();
              repaint();
         public void paint(Graphics g) {
              update(g);
         public void update(Graphics g) {
              //lets sord out double buffering
              if(offGraphics==null){
                   offIm=createImage(getSize().width,getSize().height);
                   offGraphics=offIm.getGraphics();
              if(!cards_loaded){
                   //display a message saying we're loading the cards...
                   offGraphics.setFont(new Font("Arial",Font.PLAIN,14));
                   offGraphics.setColor(new Color(171,205,239));
                   offGraphics.fillRect(0,0,getSize().width,getSize().height);
                   offGraphics.setColor(Color.black);
                   offGraphics.drawString("Loading cards... ",5,20);
                   offGraphics.drawRect(15,40, 102 ,10);
                   offGraphics.drawRect(13,38, 106 ,14);
                   offGraphics.setColor(new Color(171,205,239));
                   offGraphics.fillRect(0,0,150,35);
                   offGraphics.setColor(Color.black);
                   offGraphics.fillRect(15,40, (current_card_loading)*2 ,10);
                   offGraphics.drawString("Loading card: "+current_card_loading+1,15,20);
              }else{
                   Image currentCard;
                   while(card_width == -1)
                        card_width = deck.getCard(0).getImage().getWidth(this);
                   if(card_padding == -1)
                        card_padding = (width - (card_width * 2) - 4) / 4;
                   //clear the background...
                   offGraphics.setColor(Color.blue);
                   offGraphics.fillRect(0,0,width,height);
                   offGraphics.setColor(Color.black);
                   offGraphics.fillRect(1,1,width-2,height-2);
                   offGraphics.setColor(Color.white);
                   offGraphics.drawString("PLAYER:",card_padding,40);
                   offGraphics.drawString("DEALER:",(width/2) + card_padding,40);
                   offGraphics.drawString(message,5,height - 20);
                   if(games > 0)
                        offGraphics.drawString(games + " game(s) played...",5,height - 10);
                   //Draw the players hand...
                   for(int i=0;i<player_hand.getCardCount();i++){
                        currentCard = player_hand.getCards().getImage();
                        offGraphics.drawImage(currentCard, card_padding, 70+(20*(i-1)), this);
                   //now draw the dealers hand...
                   for(int i=0;i<dealer_hand.getCardCount();i++){
                        currentCard = dealer_hand.getCards()[i].getImage();
                        offGraphics.drawImage(currentCard, (width/2 ) + card_padding, 70+(20*(i-1)), this);
              //draw buffered image.
              g.drawImage(offIm,0,0,this);
    public void run(){
              MediaTracker t=new MediaTracker(this);
              System.out.println("Applet getting cards...");
              for(current_card_loading=0; current_card_loading < 52; current_card_loading++){
              //try{
                   card_images[current_card_loading] = getImage(getCodeBase(),
                                                                "cards/" + (current_card_loading+1) + ".gif");
                   if(card_images[current_card_loading] == null){
                        System.out.println("Null card... ["+current_card_loading+"]");
                   }else{
                        t.addImage(card_images[current_card_loading],0);
                   try{
                        t.waitForID(0);
                   }catch(InterruptedException e){
                        System.err.println("Interrupted waiting for images..>");
                   //lets show our new status.
                   repaint();
              //create the deck object now
              deck = new Deck(this,card_images);     //Create a new deck object.
              card_width = deck.getCard(0).getImage().getWidth(this);
              bHit.addActionListener(this);
              bStay.addActionListener(this);
              bRestart.addActionListener(this);
              bHit.setEnabled(false);
              bStay.setEnabled(false);
              width = getSize().width;
              height = getSize().height;
              this.add(bHit);
              this.add(bStay);
              this.add(bRestart);
              player_hand = new Hand();     //Create the hands...
              dealer_hand = new Hand();
              //make sure that the buttons appear properly.
              this.validate();
              message = "";
              cards_loaded = true;
              System.out.println("End of thread...");
              repaint();
    import java.awt.*;
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    class Deck {
         Card[] cards = new Card[52];
         int currCard;
         public Deck(Blackjack myApplet,Image[] card_images) {
              // These are the (initial) values of all the cards
              int[] values = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
              // Make all the cards, getting the images individually
              for (int i=0; i<52; i++) {
    //               Image image = myApplet.getImage(myApplet.getCodeBase(), "cards/" + (i+1) + ".gif");
                   cards[i] = new Card(card_images, values[i]);
              // Shuffle the cards.
              shuffleCards();
         public void shuffleCards(){
              Card temp;
              //loop through each card in the deck and swap it with some random card.
              for (int i=0; i<52; i++) {
                   int rand = (int)(Math.random()*52);
                   temp = cards[51-i];//take the current card...
                   cards[51-i] = cards[rand];//and swap it with some random card...
                   cards[rand] = temp;
              //now, reset the currentCard to deal...
              currCard = 0;
         public Card dealCard() {
              Card card = cards[currCard];
              currCard++;
              return card;
         public Card getCard(int i) {
              return cards[i];

    thanks for the advice.
    i've done what you suggested. but when i went try to compile the 2 programs i get error messages (shown below along with the modified code). do you know what are causing these error messages?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class Blackjack extends JFrame implements ActionListener,MouseListener{
         private Deck deck;     //The deck...
         private Hand player_hand;//player hand
         private Hand dealer_hand;//dealer hand.
         //private Button bHit=new Button("Hit");
         JButton bHit=new JButton("Hit");
         //private Button bStay=new Button("Stay");
         JButton bStay=new JButton("Stay");
         //private Button bRestart=new Button("New Game");
         JButton bRestart=new JButton("New Game");
         //lets do some double buffering.
         Image offIm=null;
         Graphics offGraphics=null;
         Dimension offDimension=null;
         Image[] card_images = new Image[52];
         private boolean cards_loaded = false;
         private int current_card_loading = 0;
         String message;                         //print a message...
         int width;          //The width of the applet
         int height;          //The height of the applet
         int card_width = -1;
         int card_padding = -1;     //How much should we pad the cards by..?
         private int games=-1;     //How many games have been played?
         public static void main(String[] args){
               Blackjack bj =new Blackjack(); 
              bj.pack();
              bj.setVisible(true);
         public Blackjack(){
            Thread card_loader = new Thread(this);
              card_loader.start();
              bHit.addMouseListener(this);
          bHit.addActionListener(this);
          //bHit.addMouseMotionListener(this);
              add(bHit);
              bStay.addMouseListener(this);
          bStay.addActionListener(this);
          //bStay.addMouseMotionListener(this);
              add(bStay);
              bRestart.addMouseListener(this);
          bRestart.addActionListener(this);
          //bRestart.addMouseMotionListener(this);
              add(bRestart);
              JFrame frame=new JFrame("BlackJack");
              frame.setSize(400,200);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.add(this);
            frame.pack();
            frame.setVisible(true);
         public void newGame(){
              bHit.setEnabled(true);
              bStay.setEnabled(false);
              player_hand = new Hand();     //Create new hands...
              dealer_hand = new Hand();
              //shuffle the deck.
              deck.shuffleCards();
              games++;
         public void hit(){
              bStay.setEnabled(true);
              player_hand.addCard(deck.dealCard());
              if(player_hand.getValue() > 21){
                   message = "You loose! (score:"+player_hand.getValue()+")";
                   //disable the hit and stay buttons...
                   bHit.setEnabled(false);
                   bStay.setEnabled(false);
                   return;
              message = "Score: "+player_hand.getValue();     
         public void stay(){
              while(dealer_hand.getValue() < 17){
                   dealer_hand.addCard(deck.dealCard());
              if(dealer_hand.getValue() <= 21 && player_hand.getValue() < dealer_hand.getValue()){
                   message = "You loose! (" + player_hand.getValue()+" - "+dealer_hand.getValue()+")";
              else if (player_hand.getValue() == dealer_hand.getValue()){
                   message = "You draw! (" + player_hand.getValue()+")";
              else{
                   message = "You win! (" + player_hand.getValue()+" - "+dealer_hand.getValue()+")";
              bHit.setEnabled(false);
              bStay.setEnabled(false);
         public void actionPerformed(ActionEvent e){
              if(e.getSource() == bRestart){
                   newGame();
              else if (e.getSource() == bHit){
                   hit();
              else if (e.getSource() == bStay){
                   stay();
              repaint();
         public void paint(Graphics g){
              update(g);
         public void update(Graphics g){
              //lets sord out double buffering
              if(offGraphics==null){
                   offIm=createImage(getSize().width,getSize().height);
                   offGraphics=offIm.getGraphics();
              if(!cards_loaded){
                   //display a message saying we're loading the cards...
                   offGraphics.setFont(new Font("Arial",Font.PLAIN,14));
                   offGraphics.setColor(new Color(171,205,239));
                   offGraphics.fillRect(0,0,getSize().width,getSize().height);
                   offGraphics.setColor(Color.black);
                   offGraphics.drawString("Loading cards... ",5,20);
                   offGraphics.drawRect(15,40, 102 ,10);
                   offGraphics.drawRect(13,38, 106 ,14);
                   offGraphics.setColor(new Color(171,205,239));
                   offGraphics.fillRect(0,0,150,35);
                   offGraphics.setColor(Color.black);
                   offGraphics.fillRect(15,40, (current_card_loading)*2 ,10);
                   offGraphics.drawString("Loading card: "+current_card_loading+1,15,20);
              else{
                   Image currentCard;
                   while(card_width == -1){
                        card_width = deck.getCard(0).getImage().getWidth(this);
                   if(card_padding == -1){
                        card_padding = (width - (card_width * 2) - 4) / 4;
                   //clear the background...
                   offGraphics.setColor(Color.blue);
                   offGraphics.fillRect(0,0,width,height);
                   offGraphics.setColor(Color.black);
                   offGraphics.fillRect(1,1,width-2,height-2);
                   offGraphics.setColor(Color.white);
                   offGraphics.drawString("PLAYER:",card_padding,40);
                   offGraphics.drawString("DEALER:",(width/2) + card_padding,40);
                   offGraphics.drawString(message,5,height - 20);
                   if(games > 0){
                        offGraphics.drawString(games + " game(s) played...",5,height - 10);
                   //Draw the players hand...
                   for(int i=0;i<player_hand.getCardCount();i++){
                        currentCard = player_hand.getCards().getImage();
                        offGraphics.drawImage(currentCard, card_padding, 70+(20*(i-1)), this);
                   //now draw the dealers hand...
                   for(int i=0;i<dealer_hand.getCardCount();i++){
                        currentCard = dealer_hand.getCards()[i].getImage();
                        offGraphics.drawImage(currentCard, (width/2 ) + card_padding, 70+(20*(i-1)), this);
              //draw buffered image.
              g.drawImage(offIm,0,0,this);
    public void run(){
              MediaTracker t=new MediaTracker(this);
              System.out.println("Frame getting cards...");
              for(current_card_loading=0; current_card_loading < 52; current_card_loading++){
              //try{
                   card_images[current_card_loading] = getImage(getCodeBase(),"cards/" + (current_card_loading+1) + ".gif");
                   if(card_images[current_card_loading] == null){
                        System.out.println("Null card... ["+current_card_loading+"]");
                   else{
                        t.addImage(card_images[current_card_loading],0);
                   try{
                        t.waitForID(0);
                   catch(InterruptedException e){
                        System.err.println("Interrupted waiting for images..>");
                   //lets show our new status.
                   repaint();
              //create the deck object now
              deck = new Deck(this,card_images);     //Create a new deck object.
              card_width = deck.getCard(0).getImage().getWidth(this);
              bHit.addActionListener(this);
              bStay.addActionListener(this);
              bRestart.addActionListener(this);
              bHit.setEnabled(false);
              bStay.setEnabled(false);
              width = getSize().width;
              height = getSize().height;
              this.add(bHit);
              this.add(bStay);
              this.add(bRestart);
              player_hand = new Hand();     //Create the hands...
              dealer_hand = new Hand();
              //make sure that the buttons appear properly.
              this.validate();
              message = "";
              cards_loaded = true;
              System.out.println("End of thread...");
              repaint();
    ----jGRASP exec: javac -g X:\NETPROG\Assignment2\Blackjack.java
    Blackjack.java:7: Blackjack is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener
    public class Blackjack extends JFrame /*Applet*/ implements ActionListener,MouseListener/*,Runnable*/{
    ^
    Blackjack.java:53: cannot find symbol
    symbol : constructor Thread(Blackjack)
    location: class java.lang.Thread
         Thread card_loader = new Thread(this);
    ^
    Blackjack.java:209: cannot find symbol
    symbol : method getCodeBase()
    location: class Blackjack
                   card_images[current_card_loading] = getImage(getCodeBase(),"cards/" + (current_card_loading+1) + ".gif");
    ^
    3 errors
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    import java.awt.*;
    import javax.swing.JFrame;
    import java.net.*;
    import java.io.*;
    class Deck {
         Card[] cards = new Card[52];
         int currCard;
         public Deck(/*Blackjack myApplet*/Blackjack myFrame,Image[] card_images) {
              // These are the (initial) values of all the cards
              int[] values = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
                   11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
              // Make all the cards, getting the images individually
              for (int i=0; i<52; i++) {
                   cards[i] = new Card(card_images, values[i]);
              // Shuffle the cards.
              shuffleCards();
         public void shuffleCards(){
              Card temp;
              //loop through each card in the deck and swap it with some random card.
              for (int i=0; i<52; i++) {
                   int rand = (int)(Math.random()*52);
                   temp = cards[51-i];//take the current card...
                   cards[51-i] = cards[rand];//and swap it with some random card...
                   cards[rand] = temp;
              //now, reset the currentCard to deal...
              currCard = 0;
         public Card dealCard() {
              Card card = cards[currCard];
              currCard++;
              return card;
         public Card getCard(int i) {
              return cards[i];
    ----jGRASP exec: javac -g X:\NETPROG\Assignment2\Deck.java
    Blackjack.java:6: Blackjack is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener
    public class Blackjack extends JFrame implements ActionListener,MouseListener{
    ^
    Blackjack.java:45: cannot find symbol
    symbol : constructor Thread(Blackjack)
    location: class java.lang.Thread
         Thread card_loader = new Thread(this);
    ^
    Blackjack.java:201: cannot find symbol
    symbol : method getCodeBase()
    location: class Blackjack
                   card_images[current_card_loading] = getImage(getCodeBase(),"cards/" + (current_card_loading+1) + ".gif");
    ^
    3 errors
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  • Opening a frame from an applet

    Hi,
    I want to open a frame in my applet. If I'm using swing, JApplet opening a JFrame, is it possible to keep the frame open if the user browses away from the page that holds the applet?
    Are there any tricks? I've tried opening it in a new Thread, but it still goes away when the the browser's page changes.
    Could I call getParent() from the applet until I get an instance of Frame (which would be the browser) and set my JFrames' parent? Or does that only work with the old Netscape and old AWT Frames?
    I basically want to know if I can keep my JFrame open until the browser is closed. Any ideas or suggestions would be greatly appreciated.
    thank you very much

    Do you want to open a jsp application in a frame when you click on the applet?If so, there is a programme in http://www.globalleafs.com -Java-Java Applets 's download section. Check it out.

  • Opening new window from applet does not pass session

    I have an applet which has a function where it opens some jsp pages in a new window. The jsp page checks for a session variable to very the user is logged in and some other variables that are required on the page. My problem is in IE 6/7 the new window does not have the session variables from the parent window.
    I'm using
    context.showDocument(new URL(host + "?" + params.toString()), "_blank");
    to open the new windows.
    How can I open a jsp age in a new window while carrying over the session variables from the parent/applet window?
    Thanks for any assistance!

    We experienced the same thing with Java 6 Update 18 on IE 7. As for IE 8, if the user is a local administrator, then the session is kept in the new browser windows opened via showDocument. Check out the following URL for related discussions:
    http://stackoverflow.com/questions/1324181/ie8-losing-session-cookies-in-popup-windows
    Our clients are forced to roll back to Java 6 Update 17. Firefox works fine.

Maybe you are looking for

  • IPod shows no music, iTunes no longer reads iPod

    I have a 4th generation 40gig iPod (non-colour). Yesterday, I plugged it into my MacBookPro, it loaded my iTunes, and I manually added a couple of songs and made a new iPod playlist. I then spent some time going through my old iPod playlists and list

  • Is UDF required for this?!! or Can we manage with Node Functions?!!!

    HI Gurus, I have a requirement like below desc, Is UDF required for this?!! or Can we manage with Node Functions?!!! Source File: ( File ) a) PO_TYPE b) Style1 c) Style2 Note: Style1 leads to Headernode and Style2 leads to ChildNode, Style1 and Style

  • Installation issue with Oracle 10G Express Edition

    I have installed both this product and the Enterprise Manager in the past (on the same laptop that I am using now), however when I try to download the file for my current class I get a dialog box that tells me that the file type is unknown and Window

  • ORA-12154: TNS:Could not resolve service name. (WIS 10901).

    HI Gurus, we have the following scenario... Weu2019ve installed Busines Objects EDGE 3.1 SP3. The server of this installation is MS Windows Server 2003 Enterprise Edition SP2, Intel ® Xeon Enterprise TM CPU 2.80 GHz 6.5 RAM. In the Server we have SAP

  • Message error from Adobe Indesign : Default font Substituted for missing do.

    Hello, Message error from Indesign : Default font substituted for missing font I am currently using version "Adobe InDesign CS6 Middle East," which normally supports the Arabic language ... The problem is that the characters display correctly and oth