Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Image buffereing?  (Read 1932 times)
0 Members and 1 Guest are viewing this topic.
Offline jamesco

Senior Newbie





« Posted 2006-11-23 01:47:25 »

hi i have this problem when other user sent message over it pop up a JOptionPane

and i can't see the content why this happens?

it happens when i paint more then 1

 g.drawImage



Offline fletchergames

Senior Member





« Reply #1 - Posted 2006-11-23 19:39:07 »

If you're trying to draw an image on top of the JOptionPane, it won't work because dialogs are in a layer above the rest of Swing.  This means that the dialogs get drawn on top of everything else.

You need to write a class that extends JOptionPane (or perhaps JDialog) and modify the paintComponent method.  Alternatively, you could make a JDialog and just add Swing components to it to make it look like a JOptionPane with images.  You can display an image as the icon for a JLabel (using the ImageIcon class to create the Icon).
Offline jamesco

Senior Newbie





« Reply #2 - Posted 2006-11-24 00:55:05 »

ok thanks alot i will try it out =) Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jamesco

Senior Newbie





« Reply #3 - Posted 2006-11-24 01:47:37 »

i have a

public class ValidatorDialog extends JDialog

it pops up only when i need to log in but it's also having the problem

if you need any codes? i can paste it here not sure which codes do you all need to see

thanks for the expert advice

in the below picture

it has 2 label, 2 text field, 1 button

for the button and textfield need to click on it for it to appear

or drag the box larger the contents will appear



Offline fletchergames

Senior Member





« Reply #4 - Posted 2006-11-25 04:32:26 »

It sounds like you're having a problem with the layout now.  Try calling ValidatorDialog.pack after adding all the components to the ValidatorDialog.

If you're using a null layout, you have to set the position and the size of the components.  It doesn't sound like you're using a null layout because resizing the dialog causes things to appear.

Have you tried just making it start out bigger?

By the way, you can use ValidatorDialog.setLocation to make the ValidatorDialog appear in the middle of the frame.

If none of this helps, post the code where you're creating the ValidatorDialog, where you're creating components and adding them to the ValidatorDialog, and where you're displaying the ValidatorDialog.
Offline jamesco

Senior Newbie





« Reply #5 - Posted 2006-11-28 03:47:46 »

ok i will try it out thanks
Offline jamesco

Senior Newbie





« Reply #6 - Posted 2006-12-01 01:41:45 »

this is where i create my VD


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
   public ValidatorDialog(Frame parent, Callback[] cbs) {
        super(parent, "Validation Information Required", true);
        callbacks = cbs;
        Container c = getContentPane();
        JPanel validationPanel = new JPanel();
        validationPanel.setLocation(200,200);
       
        validationPanel.setLayout(new GridLayout(2, 0));
        c.add(validationPanel, BorderLayout.NORTH);
        JButton validateButton = new JButton("CONTINUE");
        c.add(validateButton, BorderLayout.SOUTH);

        // when pressed, set the data from the UI components to the
       // matching CallBacks.
       validateButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                transcribeToCallbacks();
                ValidatorDialog.this.setVisible(false);
                ValidatorDialog.this.getParent().remove(ValidatorDialog.this);
            }
        });

        // Iterate through the javax.security.auth.callback.CallBacks
       // and render the appropriate UI accordingly.
       // For each CallBack, the matching UI Component is stored in
       // the dataFields array. The order is important, as they will
       // be retrieved along side their matching CallBack.
       for (Callback cb : cbs) {
            if (cb instanceof ChoiceCallback) {
                ChoiceCallback ccb = (ChoiceCallback) cb;
                validationPanel.add(new JLabel(ccb.getPrompt()));
                JComboBox combo = new JComboBox(ccb.getChoices());
                combo.setSelectedItem(ccb.getDefaultChoice());
                validationPanel.add(combo);
                dataFields.add(combo);
            } else if (cb instanceof ConfirmationCallback) {
                ConfirmationCallback ccb = (ConfirmationCallback) cb;
                validationPanel.add(new JLabel(ccb.getPrompt()));
                JComboBox combo = new JComboBox(ccb.getOptions());
                combo.setSelectedItem(ccb.getDefaultOption());
                validationPanel.add(combo);
                dataFields.add(combo);
            } else if (cb instanceof NameCallback) {
                NameCallback ncb = (NameCallback) cb;
                validationPanel.add(new JLabel(ncb.getPrompt()));
                JTextField nameField = new JTextField(ncb.getDefaultName());
                validationPanel.add(nameField);
                dataFields.add(nameField);
            } else if (cb instanceof PasswordCallback) {
                PasswordCallback ncb = (PasswordCallback) cb;
                validationPanel.add(new JLabel(ncb.getPrompt()));
                JPasswordField passwordField = new JPasswordField();
                validationPanel.add(passwordField);
                dataFields.add(passwordField);
            } else if (cb instanceof TextInputCallback) {
                TextInputCallback tcb = (TextInputCallback) cb;
                validationPanel.add(new JLabel(tcb.getPrompt()));
                JTextField textField = new JTextField(tcb.getDefaultText());
                validationPanel.add(textField);
                dataFields.add(textField);
            } else if (cb instanceof TextOutputCallback) {
                TextOutputCallback tcb = (TextOutputCallback) cb;
                validationPanel.add(new JLabel(tcb.getMessage()));

            }
        }
        pack();
        setVisible(true);
       
    }


----------------------------------------------------------------------------------------

and i call my VD in the class Login.java


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   public void validationRequest(Callback[] callbacks) {
      // TODO Auto-generated method stub
       status.setText("Status: Validating...");
        ValidatorDialog v = new ValidatorDialog(this, callbacks);
        v.setLocation(200, 200);
       
        game.setMsg(v.getUserName());
        //uname  = v.getUserName();
       mgr.sendValidationResponse(callbacks);
        v.pack();
   }
Offline fletchergames

Senior Member





« Reply #7 - Posted 2006-12-01 19:34:59 »

My advice to you is to avoid BorderLayout because it's terrible.

Change the layout of the content pane to use a vertical BoxLayout.  To add a label and a text field next to eachother, add them to a horizontal box, and add the horizontal Box to the content pane.

Finally, add the button to the content pane.  If there are more than 1 button, add them all in a horizontal Box.

You might be able to still use the GridLayout for the labels and text fields even after converting the content pane to a vertical BoxLayout.  I usually work with Boxes because they seem to work a little bit better.

Box contains some special methods (such as createGlue) that you may want to use as well, though I don't think they'll be necessary in this instance.
Offline jamesco

Senior Newbie





« Reply #8 - Posted 2006-12-06 03:20:37 »

mmm still no difference
Offline jamesco

Senior Newbie





« Reply #9 - Posted 2006-12-08 07:55:21 »

i have solve it , it's having problems with repaint() ;

thanks for your help i have also convert to BoxLayout =) no harm trying but useful =) Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2006-12-10 01:28:50 »

fletchergames, please read the first-post very carefully, he's having a whole other problem than you seem to think.

The problem is that the contents of a Dialog isn't shown, when it should. He's not trying to paint images in his dialogs. LayoutManagers have even less to do with it.



I don't really know the problem, nor it's solution, but you can try this:

Ensure you do all your UI-code on the EventDispatchThread (EDT)

1  
2  
3  
4  
5  
6  
7  
8  
9  
SwingUtilities.invokeLater(new Runnable(){
   public void run()
   {
      Dialog d = new Dialog(SET_THE_PARENT___NOT_NULL, modal=true);
      ...
      d.pack();
      d.setVisible();
   }
});

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 800
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2006-12-10 01:30:57 »

i have solve it , it's having problems with repaint() ;

thanks for your help i have also convert to BoxLayout =) no harm trying but useful =) Grin

It should never have problems with repaint. don't call repaint manually to 'fix' it, because there's something wrong, that causes the repaint not to occur automaticly. Better solve that! (try what i said in my previous post)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline jamesco

Senior Newbie





« Reply #12 - Posted 2006-12-12 03:00:35 »

It should never have problems with repaint. don't call repaint manually to 'fix' it, because there's something wrong, that causes the repaint not to occur automaticly. Better solve that! (try what i said in my previous post)

well thanks for your guide.

as for repaint() in my case i called an extra repaint

    public void paint(Graphics g) {
       super.paint(g);
       Graphics2D g2 = (Graphics2D)g;

        for(across = 0; across < width ; across++) {
            for(vert = 0; vert < height ; vert++) {
                if (A[vert][across] == 1)
                {

                    g2.drawImage(gras,across*32,vert*32,this);
                }
               
                else if(A[vert][across]==2)
                {
                    g2.drawImage(tree,across*32,vert*32,this);

                 }
               
                else if(A[vert][across]==3)
                {

                    g2.drawImage(mount,across*32,vert*32,this);

               }
               
                else if(A[vert][across]==4)
                {

                    g2.drawImage(seamount,across*32,vert*32,this);
                   
               }
               
                else if(A[vert][across]==5)
                {

                  g2.drawImage(sea,across*32,vert*32,this);   
                  
               }
               
                else if(A[vert][across]==6)
                {

                  g2.drawImage(sbr,across*32,vert*32,this);   
                  
               }
               
                else if(A[vert][across]==7)
                {

                  g2.drawImage(sbl,across*32,vert*32,this);   
                  
               }
               
                else if(A[vert][across]==8)
                {
                  
                  g2.drawImage(str,across*32,vert*32,this);   
                  
               }
               
                else if(A[vert][across]==9)
                {
                  
                  g2.drawImage(stl,across*32,vert*32,this);   
                  
               }
               
                else if(A[vert][across]==10)
                {
                  
                  g2.drawImage(shoretop,across*32,vert*32,this);   
                  
               }
               
                else if(A[vert][across]==11)
                {
                  
                  g2.drawImage(shoreleft,across*32,vert*32,this);   
                  
               }
               
                else if(A[vert][across]==12)
                {
                  
                  g2.drawImage(shorebottom,across*32,vert*32,this);   
                  
               }

                else
               {
                  
                  g2.drawImage(shoreright,across*32,vert*32,this);   
                  
               }
            }
        }

        g2.setColor(Color.cyan);
       g2.drawString(uname,x,y-10);
       g2.drawImage(pship, x, y,this);
       

       for(int i = 0;i< Login.q;i++)
       {
          //String nu = Login.nUser;
           g2.drawString(Login.nUser,xX,yY-10);
           g2.drawImage(pship, xX, yY, this);

       }
//as u can see, when i remove this repaint , i do not have that problem
not sure why but i seems that it's repainting a blank stuff.

repaint();
       
    }
Offline fletchergames

Senior Member





« Reply #13 - Posted 2006-12-12 19:45:32 »

You should never call repaint from within the paint or paintComponent methods because repaint just calls the paint method again.

Also, why don't you just put all the images in an array (or ArrayList or enum or something) instead of having all those if statements?  You're just doing extra typing and making your code harder to modify.
Offline jamesco

Senior Newbie





« Reply #14 - Posted 2006-12-13 01:30:16 »

oh ok thanks alot! i'll try the array way =) thanks
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Grunnt (5 views)
2014-09-23 14:38:19

radar3301 (13 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (75 views)
2014-09-10 13:57:51

TehJavaDev (104 views)
2014-09-10 06:39:09
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!