A good way to develop GUI ?
Page 1 of 18 Replies - 449 Views - Last Post: 26 April 2011 - 07:35 AM
#1
A good way to develop GUI ?
Posted 25 April 2011 - 06:36 PM
I have a class called Table which extends JFrame. I'll use it to display a poker table, so it will have a few JButtons, labels, images and I'll also try to add a chat box(not sure what to use for that yet) I'm not very experienced with graphics and I'm not sure what's the right way to develop the table.
At the moment I'm using paint() to draw the background and table images. The buttons and labels I add to a JPanel. The problem is that only one of the buttons shows up when I start the application and the rest appear when I move the mouse over their supposed location. If I don't override paint, all buttons show up.
What should I do? Stop overriding paint and display the images in a label or try to draw the buttons from within paint(can I do that?) I doubt both are good ideas, so if anyone knows a better way to do it, please let me know.
Thanks
Replies To: A good way to develop GUI ?
#2
Re: A good way to develop GUI ?
Posted 25 April 2011 - 08:30 PM
public void paint(Graphics g) {
super.paint(g); // to draw the background and the JComponent
// my personal drawing
... here
}
#3
Re: A good way to develop GUI ?
Posted 26 April 2011 - 04:12 AM
public void paint(Graphics g)
{
g.drawImage(backImage,0,0,null);
g.drawImage(tableImage,100,80,null);
buildPanel();
}
buildPanel() is used to add the different components.
public void buildPanel()
{
panel.setLayout(null);
panel.add(callButton);
callButton.setBounds(300,440,70,30);
#4
Re: A good way to develop GUI ?
Posted 26 April 2011 - 04:23 AM
public void paint(Graphics g)
{
g.drawImage(backImage,0,0,null);
g.drawImage(tableImage,100,80,null);
}[code]
buildPanel() is used to add the different components.
public void buildPanel()
{
panel.setLayout(null);
panel.add(callButton);
callButton.setBounds(300,440,70,30);
add(panel);
}[code]
I call buildPanel in the constructor of the Table object. I tried using super.paint(g) but got the same results
PS: Aaarhg, sorry for the earlier post, sosmehow submitted it before finishing
This post has been edited by damiencourt: 26 April 2011 - 04:26 AM
#5
Re: A good way to develop GUI ?
Posted 26 April 2011 - 04:36 AM
public void paint(Graphigs g) {
// Draw any backgrounds here (underneath the buttons)
// Now get Java to draw all the buttons for you.
super.paint(g);
// Draw any foregrounds here (on top of the buttons)
}
This post has been edited by cfoley: 26 April 2011 - 04:36 AM
#6
Re: A good way to develop GUI ?
Posted 26 April 2011 - 06:22 AM
I made the code as simple as possible and posted it below. It's pretty straightforward so I removed the comments as well to make it shorter. I hope you'll spot what Im doing wrong.
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
public class Table extends JFrame
{
private BufferedImage tImage = null;
private BufferedImage bImage = null;
private JButton foldButton = new JButton("Fold");
private JButton callButton = new JButton("Call");
private JButton x2 = new JButton("2x");
private JButton x3 = new JButton("3x");
private JPanel panel = new JPanel();
private String path = "table.png";
private String path2 = "bg.jpg";
public Table()
{
loadImages();
setSize(880,600);
buildPanel();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void buildPanel()
{
panel.setLayout(null);
panel.add(callButton);
panel.add(foldButton);
panel.add(x2);
panel.add(x3);
foldButton.setBounds(200,440,70,30);
callButton.setBounds(300,440,70,30);
x2.setBounds(200,500,50,30);
x3.setBounds(260,500,50,30);
add(panel);
}
public void loadImages()
{
try
{
bImage = ImageIO.read(new File(path2));
tImage = ImageIO.read(new File(path));
}catch (IOException ex){ ex.printStackTrace();}
}
public void paint(Graphics g)
{
g.drawImage(bImage,0,0,null);
g.drawImage(tImage,100,80,null);
//super.paint(g);
}
}
This post has been edited by damiencourt: 26 April 2011 - 06:24 AM
#7
Re: A good way to develop GUI ?
Posted 26 April 2011 - 06:27 AM
#8
Re: A good way to develop GUI ?
Posted 26 April 2011 - 06:33 AM
If I don't call it everything shows up, but in the manner I explained above
I just noticed that the only button that gets displayed immediately is the one that is the closest to the top left corner...
This post has been edited by damiencourt: 26 April 2011 - 06:43 AM
#9
Re: A good way to develop GUI ?
Posted 26 April 2011 - 07:35 AM
|
|

New Topic/Question
Reply



MultiQuote




|