JPanel or JFrame

Hi,
Just a quick question, which is better
public class editor extends JPanel {
or
public class editor extends JFrame {
Thanks
Ger

Good book will explain the difference, which you really need so you can understand the level of inheritance from Object class on down. Otherwise you will be doomed to posting meaningless, pointless questions....

Similar Messages

  • Problem with JPanel in JFrame

    hai ashrivastava..
    thank u for sending this one..now i got some more problems with that screen .. actually i am added one JPanel to JFrame with BorderLayout at south..the problem is when i am drawing diagram..the part of diagram bellow JPanel is now not visible...and one more problem is ,after adding 6 ro 7 buttons remaing buttons are not vissible..how to increase the size of that JPanel...to add that JPanel i used bellow code
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    f.getContentPane().add(BorderLayout.SOUTH, panel);

    Hi
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    // Add this line to ur code with ur requiredWidth and requiredHeight
    panel.setPreferredSize(new Dimension(requiredWidth,requiredHeight));
    f.getContentPane().add(BorderLayout.SOUTH, panel);
    This should solve ur problem
    Ashish

  • Embedding PDF File into JPanel or JFrame

    Does anyone know how to embedd a PDF file or document into a JPanel or JFrame.

    I can suggest you ways
    1)pdf to Image
    2)pdf to html
    http://www.verypdf.com/pdf2htm/
    Free online service
    http://www.gohtm.com/

  • Beginners Questions about Multiple JPanels in JFrame and event handling

    I am a newbie with SWING, and even a newerbie in Event Handling. So here goes.
    I am writing a maze program. I am placing a maze JPanel (MazePanel) at the center of a JFrame, and a JPanel of buttons (ButtonPanel) on the SOUTH pane. I want the buttons to be able to re-randomize the maze, solve the maze, and also ouput statistics (for percolation theory purposes). I have the backbone all done already, I am just creating the GUI now. I am just figuring out EventHandlers and such through the tutorials, but I have a question. I am adding an ActionListener to the buttons which are on the ButtonPanel which are on JFrame (SOUTH) Panel. But who do I make the ActionListener--Basically the one doing the work when the button is pressed. Do I make the JFrame the ActionListener or the MazePanel the ActionListener. I need something which has access to the maze data (the backbone), and which can call the Maze.randomize() function. I'm trying to make a good design and not just slop too.
    Also I was wondering if I do this
    JButton.addActionListener(MazePanel), and lets say public MazePanel implments ActionListenerdoesn't adding this whole big object to another object (namely the button actionlistener) seem really inefficient? And how does something that is nested in a JPanel on JFrame x get information from something nested in another JPanel on a JFrame x.
    Basically how is the Buttons going to talk to the maze when the maze is so far away?

    I'm not an expert, but here's what I'd do....
    You already have your business logic (the Maze classes), you said. I'm assuming you have some kind of public interface to this business logic. I would create a new class like "MazeGui" that extends JFrame, and then create the GUI using this class. Add buttons and panels as needed to get it to look the way you want. Then for each button that does a specific thing, add an anonymous ActionListener class to it and put whatever code you need inside the ActionListener that accesses the business logic classes and does what it needs to.
    This is the idea, though my code is totally unchecked and won't compile:
    import deadseasquirrels.mazestuff.*;
    public class MazeGui extends JFrame {
      JPanel buttonPanel = new JPanel();
      JPanel mazePanel = new JPanel();
      JButton randomizeB = new JButton();
      JButton solveB = new JButton();
      JButton statsB = new JButton();
      // create instanc(es) of your Maze business logic class(es)
      myMaze = new MazeClass();
      // add the components to the MazeGui content pane
      Component cp = getContentPane();
      cp.add(); // this doesn't do anything, but in your code you'd add
                // all of your components to the MazeGui's contentpane
      randomizeB.addActionListener(new ActionListener {
        void actionPerformed() {
          Maze newMaze = myMaze.getRandomMazeLayout();
          mazePanel.setContents(newMaze); // this is not a real method!
                                          // it's just to give you the idea
                                          // of how to manipulate the JPanel
                                          // representing your Maze diagram,
                                          // you will probably be changing a
                                          // subcomponent of the JPanel
      solveB.addActionListener(new ActionListener {
        void actionPerformed() {
          Solution mySolution = myMaze.getSolution();
          mazePanel.setContents(mySolution); // again, this is not a real
                                             // method but it shows you how
                                             // the ActionListener can
                                             // access your GUI
      // repeat with any other buttons you need
      public static void main(String[] args) {
        MazeGui mg = new MazeGui();
        mg.setVisible(true);
        // etc...
    }

  • How can i transform MFC HWND into jpanel or jframe instance

    Hi!
    I want to open a MFC window, then with the HWND , i want to open java subwindow created inside the MFC window with the HWND, i wonder if there is a way. how can i transform the HWND into jpanel or jframe instance.

    Look at the article in CodeProject and read the example in it. The other questions you can send to my email because I cannot give you concrete response in this forum.

  • Embeding PDF file into JPanel or JFrame

    Do any one have an idea on how to embed a PDF file into JPanel or JFrame?

    I can suggest you ways
    1)pdf to Image
    2)pdf to html
    http://www.verypdf.com/pdf2htm/
    Free online service
    http://www.gohtm.com/

  • Help! Read raw Image data from a file and display on the JPanel or JFrame.

    PLEASE HELP, I want to Read Binary(Raw Image)data (16 bit integer) from a file and display on the JPanel or JFrame.

    Hey,
    I need to do the same thing. Did you find a way to do that?
    Could you sent me the code?
    It's urgent, please.
    My e-mail is [email protected]

  • How do you set an image into the background of a JPanel or JFrame?

    How do you set an image into the background of a JPanel or JFrame?

    Something like this, Ive thrown in an ImageIcon on a
    button too for good measure.
    import java.awt.*;
    import javax.swing.*;
    public class JFrameImage extends JFrame {
    public JFrameImage() {
    Container c    = getContentPane();
    JPanel panel = new JPanel(){
                 public void paintComponent(Graphics g)     {
    ImageIcon img = new
    = new ImageIcon("background.jpg");
                      g.drawImage(img.getImage(), 0, 0, null);
                      super.paintComponent(g);
            panel.setOpaque(false);
    ImageIcon icon = new ImageIcon("onButton.jpg");
    JButton button = new JButton(icon);
    panel.add(button);
    c.add(panel);
    public static void main(String[] args) {
    JFrameImage frame = new JFrameImage();
    frame.setSize(200,200);
    frame.setVisible(true);
    Going totally fancy pants
    ImageIcon bigImage = new ImageIcon(bgImage.getImage().getScaledInstance(getWidth(), getHeight(),Image.SCALE_REPLICATE));
    g.drawImage(bigImage.getImage(), 0, 0, this); Will scale the image to the size of the panel
    whereas
    for (int y = 0; y  < getHeight(); y = y + image.getHeight(null))
    for (int x = 0; x< getWidth(); x = x + image.getWidth(null))
    g.drawImage(image, x, y, this); Will give a tiled effect
    Try tiling with an animated gif and bring your processor to a standstill.

  • How to embed a Jpanel in JFrame

    I have made two JPanel classes
    JPanelclass1
    JPanelclass2
    and a JFrame class
    JFrameclass1
    in netbean 5.5.1
    I want to embed that JPanel in the JFrame and when a button is clicked the ist JPanel dissaper and the second JPanel appears on the same JFrame..... i have tried to declare an object of that JPanel class in the JFrame
    Please Help

    One word: CardLayout

  • JPanel in jFrame

    Hello
    I have a class pannel1.java which is basicly a jpannel
    public class pannel1 extends javax.swing.JPanel {
    public pannel1() {
    initComponents();
    Now i have a different class which is basicly a jframe
    How can i display the jpannel class into the jframe class ?

    Read through the tutorials as recommended. However, in answer to your question, something like this.
    public class Class1 extends JPanel {
      //all your methods and jpanel sizes ommitted
    public class Main {
      public static void main(String[] args) {
         JFrame f = new JFrame();
        Class1 cl = new Class1();
         f.add(cl);
         f.setVisible(true);
    }Hope that helps.
    You can do others such as getContentPane().setContentPane(cl).
    This is just to get you started. All thread safety features have been ommited. Read about Swing thread safety after you get some understanding of Java Swing.

  • Weird problem with jpanel vs jframe

    I'm using jmathplot.jar from JMathTools which lets me do 3d plotting. I used a JFrame to get some code to work and it worked fine. Here's the code that worked for a JFrame:
    public class View extends JFrame
        private Model myModel;
        private Plot3DPanel myPanel;
        // ... Components
        public View(Model m)
            myModel = m; 
            // ... Initialize components
            myPanel = new Plot3DPanel("SOUTH");
            myPanel.addGridPlot("Test",myModel.getXRange(),myModel.getYRange(),myModel.getZValues());
            setSize(600, 600);
            setContentPane(myPanel);
            setVisible(true);
    }Here's the class that starts everything:
    public class TestApplet extends JApplet
        public void init()
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try
                SwingUtilities.invokeAndWait(new Runnable()
                    public void run()
                        createGUI();
            catch (Exception e)
                e.printStackTrace();
        private void createGUI()
            System.out.println("Creating GUI");
            Model model = new Model();
            View view = new View(model);
    }And here's the Model:
    public class Model
        private double[] myXRange,myYRange;
        private double[][] myZValues;
        public Model()
            createDataSet();
        public double[] getXRange()
            return myXRange;
        public double[] getYRange()
            return myYRange;
        public double[][] getZValues()
            return myZValues;
        private void createDataSet()
            myXRange = new double[10];
            myYRange = new double[10];
            myZValues = new double[10][10];
            for(double i=0;i<10;i++)
                for(double j=0;j<10;j++)
                    double x = i/10;
                    double y = j/10;
                    myXRange[(int) i] = x;
                    myYRange[(int) j] = y;
                    myZValues[(int) i][(int) j]= Math.cos(x*Math.PI)*Math.sin(y*Math.PI);
    }However, as you can see, my main class is a JApplet because ideally I want View to be a JPanel that I add to the applet. All I did was change "extends JFrame" to "extends JApplet" and changed:
    setSize(600, 600);
    setContentPane(myPanel);
    setVisible(true);to
    this.add(myPanel);and added these two lines to createGUI():
            view.setOpaque(true);
            setContentPane(view);When I run it however, it appears really really small. It seems like its drawing the panel to the default size of the applet viewer and doesn't resize it when I resize the applet. I don't know if it's a problem with the library or if I'm doing something wrong in my applet.

    However, as you can see, my main class is a JApplet because ideally I want View to be a JPanel that I add to the applet. All I did was change "extends JFrame" to "extends JApplet" and (...)What do you mean? View extends JApplet? I thought View was meant to extend JPanel in the end...
    When I run it however, it appears really really small. It seems like its drawing the panel to the default size of the applet viewer and doesn't resize it when I resize the applet.Or, the panel has its preferred size, and this latter is too small. Actually the panel has the size its container's layout manager awards it (taking or not the panel's preferred, minimum, and maximum sizes into account). See the tutorial on [layout managers|http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html] .
    In particular, this line adds the myPanel to a parent panel (presumably, it is in class View which extends JPanel, whose default layout is FlowLayout):
    this.add(myPanel);
    I don't know if it's a problem with the library or if I'm doing something wrong in my applet.Likely not (presumably the library interfers only in how it computes the Plot3DPanel's preferred size). There's an easy way to tell: try to layout correctly a custom JPanel of yours, containing only e.g. a button with an icon. Once you understand the basics of layout management, revisit the example using ther 3rd-party library.
    N.B.: there are a lot of "likely" and "presumably" in my reply: in order to avoid hardly-educated guesses especially on what is or isn't in your actual code, you'd better provide an SSCCE , which means reproducing the problem without the 3rd party library.

  • Adding Canvas3D image to a JPanel or JFrame

    My team has developed a 3D game board and we want to add it to a JPanel. The test code below works fine but we want to add this to a JPanel. Can you put a Canvas3D in a JPanel?
    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.Frame;
    import java.awt.event.*;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import java.awt.event.*;
    import java.util.Enumeration;
    import com.sun.j3d.utils.behaviors.mouse.*;
    import com.sun.j3d.utils.behaviors.keyboard.*;
    public class ProxyBoard extends Applet
         public class SimpleBehave extends Behavior
              private TransformGroup targetTG;
              private Transform3D rotation = new Transform3D();
              private double angle = 0.0;
              SimpleBehave(TransformGroup targetTG)
                   this.targetTG = targetTG;
              public void initialize()
                   this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
              public void processStimulus(Enumeration criteria)
                   angle +=0.05;
                   rotation.rotX(angle);
                   targetTG.setTransform(rotation);
                   this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
         public ProxyBoard()
              setLayout(new BorderLayout());
              Canvas3D canvas3D = new Canvas3D(null);
              add("Center", canvas3D);
              SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
              simpleU.getViewingPlatform().setNominalViewingTransform();
              BranchGroup scene = createSceneGraph(simpleU);
              scene.compile();
              simpleU.addBranchGraph(scene);
         public BranchGroup createSceneGraph(SimpleUniverse su)
              BranchGroup boardBG = new BranchGroup();
              TransformGroup vpTrans = null;
              BoundingSphere mouseBounds = null;
              vpTrans = su.getViewingPlatform().getViewPlatformTransform();
              mouseBounds = new BoundingSphere(new Point3d(), 1000.0);
              KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
              keyNavBeh.setSchedulingBounds(mouseBounds);
              boardBG.addChild(keyNavBeh);
              MouseRotate myMouseRotate = new MouseRotate(MouseBehavior.INVERT_INPUT);
              myMouseRotate.setTransformGroup(vpTrans);
              myMouseRotate.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseRotate);
              MouseTranslate myMouseTranslate = new MouseTranslate(MouseBehavior.INVERT_INPUT);
              myMouseTranslate.setTransformGroup(vpTrans);
              myMouseTranslate.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseTranslate);
              MouseZoom myMouseZoom = new MouseZoom(MouseBehavior.INVERT_INPUT);
              myMouseZoom.setTransformGroup(vpTrans);
              myMouseZoom.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseZoom);
              Board board = new Board();
              Transform3D pegPositions[] = new Transform3D[8];
              TransformGroup pegPositionsTG[] = new TransformGroup[8];
              Pegs pegs[] = new Pegs[8];
              Transform3D translate = new Transform3D();
              translate.set(new Vector3f(0.0f, -1.0f, -5.0f));
              TransformGroup boardTGT1 = new TransformGroup(translate);
              TransformGroup boardTGR1 = new TransformGroup();
              boardTGR1.setCapability(boardTGR1.ALLOW_TRANSFORM_WRITE);
              for(int i = 0; i < 8; i++)
                   pegs[i] = new Pegs();
                   pegPositions[i] = new Transform3D();
                   pegPositions.set(new Vector3f(-2.5f, 0, (float)(-i/4.0)));
                   pegPositionsTG[i] = new TransformGroup(pegPositions[i]);
                   pegPositionsTG[i].addChild(pegs[i].getTransformGroup());
                   boardTGT1.addChild(pegPositionsTG[i]);               
              boardTGR1.addChild(board.getBoard());
              SimpleBehave myRotate = new SimpleBehave(boardTGR1);
              myRotate.setSchedulingBounds(new BoundingSphere());
              boardBG.addChild(myRotate);
              boardTGT1.addChild(boardTGR1);
              boardBG.addChild(boardTGT1);                    
              boardBG.compile();
              return boardBG;
         public static void main(String[] args)
              Frame frame = new MainFrame(new ProxyBoard(), 800, 600);
    /*-------------Main Source Container------------------*/
    public class Proxy extends JFrame
         implements MouseMotionListener
         private JDesktopPane myDesktop;
         private JPanel panel;
         private JLabel statusBar, position;
         private JSlider zSlide, zSlide1;
         private ImageIcon test;
         private int i;
         public Proxy()
              super("Proxy Board Prototype 1.2.2");
              i=0;
              statusBar = new JLabel();
              getContentPane();
              myDesktop = new JDesktopPane();
              getContentPane().add(myDesktop);
    public static void main(String args[])
              Proxy app = new Proxy();
              //new MainFrame( new Proxy(), 800, 600 );
    //          app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    /*-------------JPanel I want to hold to the 3D Graphics--------*/
    class Session extends JPanel
         implements MouseMotionListener
         private ImageIcon test;
         private JLabel position;
         private JSlider zSlide;
         private JPanel panel, gPanel;
         static int openFrameCount = 0;
         public Session()
              //super("", true, true, true, true);
              setLayout(new FlowLayout());
              openFrameCount++;
         //setTitle("Untitled Message " + openFrameCount);
    ProxyBoard pb = new ProxyBoard();//<-Graphic Class
    gPanel = new JPanel();
    gPanel.add(pb);//<-I want the 3D Graphic here
              test = new ImageIcon("Layout.jpg");
              JLabel pic = new JLabel(test);
              addMouseMotionListener( this );
              zSlide = new JSlider(SwingConstants.VERTICAL, 600, 10);
              zSlide.setMajorTickSpacing(25);
              zSlide.setPaintTicks(true);
              zSlide.setToolTipText("Zoom");
              panel.add(zSlide, BorderLayout.NORTH);
              panel.add(gPanel, BorderLayout.CENTER);//<-Graphic Here
              panel.add(position, BorderLayout.SOUTH);
              add(panel);
              //pack();
              setSize(200,200);
              setVisible (true);

    Yes you can. Just use the add method of JPanel. However note this
    http://www.j3d.org/faq/swing.html (specially read this: http://java.sun.com/products/jfc/tsc/articles/mixing/)
    when mixing Lightweight (JPanel) and Heavyweight (Canvas3D) components.

  • JTable on JPanel on JFrame, not appearing

    I can't see the JTable that I was expecting to between the two labels, any ideas why?
    public class Workout extends JFrame {
            final String[] exercisesDoneColumnNames = {"Exercise", "# Sets", "Set 1", "Set 2", "Set 3", "Set 4", "Set 5", "Set 6", "Set 7", "Set 8", "Set 9", "Set 10"};
            private ExercisesDoneTable myModel = new ExercisesDoneTable exercisesDoneColumnNames,0);
            private JTable table = new JTable(myModel);
            public Workout() {
                super.setTitle("Workout");
                buildExerciseDoneTable();
                Toolkit tk = Toolkit.getDefaultToolkit();
                Dimension d = new Dimension();
                d = tk.getScreenSize();
                setSize((int)d.getWidth(), (int)d.getHeight());
                setLocation(0,0);
                super.setName("Workout");
                addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent evt) {   
                        System.exit(0);
                JPanel p = new JPanel();
                p.setBackground(java.awt.Color.white);
                p.add(new JLabel("left of"));
                p.add(table);
                p.add(new JLabel("right of"));
                getContentPane().add(p);
                setVisible(true);
        //helper method just splits the code to make it more readable
        private void buildExerciseDoneTable(){
            table.setPreferredScrollableViewportSize(new Dimension(500,100));
            myModel.addTableModelListener(myModel);
            table.setVisible(true);
        }

    JPanel has a default FlowLayout.
    I think you table is there, but is not displaying anything as you have specified 0 rows when creating your table model. Change that number to 1 and you will see it appear.

  • Repost:  JPanel or JFrame Problem?

    Hello Everyone,
    I am working on a solitaire program. I am able to run and compile the program. Every time I resize the frame, I get small gray squares to the right of my buttons. Also, my cards get changed every time I resize the frame. Any suggestions are appreciated.
    Thanks,
    E
    //SolitaireProject.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class SolitaireProject extends JApplet
    public SolitaireProject()
    this.setContentPane(new SolitaireProjectPanel());
    public static void main(String[] args)
    JFrame window = new JFrame();
    window.setTitle("Solitaire by E");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setContentPane(new SolitaireProjectPanel());
    window.pack();
    window.show();
    //SolitaireProjectPanel.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.applet.*;
    public class SolitaireProjectPanel extends JPanel
    private static final int CARD_WIDTH = 77;
    private static final int CARD_HEIGHT = 110;
    private final int ACES_DISTANCE_BETWEEN_CARDS = 97;
    private final int ACES_DISTANCE_FROM_LEFT = 425;
    private final int ACES_DISTANCE_FROM_TOP = 50;
    private final int ACES_MAXIMUM = 793;
    private final int PLAYCARDS_DISTANCE_FROM_LEFT = 300;
    private final int PLAYCARDS_DISTANCE_FROM_TOP = 200;
    private final int PLAYCARDS_DISTANCE_BETWEEN_COLUMNS = 87;
    private final int PLAYCARDS_DISTANCE_BETWEEN_ROWS_FACEDOWN = 5;
    private final int PLAYCARDS_DISTANCE_BETWEEN_ROWS_FACEUP = 30;
    private final int PLAYCARDS_MAXIMUM = 899;
    private final int PILE_DISTANCE_FROM_LEFT = 75;
    private final int PILE_DISTANCE_FROM_TOP = 50;
    private final int SHOWCARD_DISTANCE_FROM_LEFT = 75;
    private final int SHOWCARD_DISTANCE_FROM_TOP = 200;
    private int _initX = 0; // x coord - set from drag
    private int _initY = 0; // y coord - set from drag
    private Card[] _cardFronts = new Card[52]; //Creates an array of cards
    private Card _currentCard = null; //Current draggable card
    private Card[] _cardBacks = new Card[52];
    public SolitaireProjectPanel()
    String suits = "CDHS";
    String faces = "A23456789TJQK";
    int cardPosition = 0;
    int crdBackPosition = 0;
    for(int suit = 0; suit < suits.length(); suit++)
    for(int face = 0; face<faces.length(); face++)
    ImageIcon img = new ImageIcon("card " + faces.charAt(face) + suits.charAt(suit) + ".jpg");
    Image image = img.getImage();
    Image scaledImage = image.getScaledInstance(77, 110, Image.SCALE_FAST);
    img.setImage(scaledImage);
    _cardFronts[cardPosition ++] = new Card (img, _initX++, _initY++);
    for(int crdBack = 0; crdBack < 52; crdBack++)
    ImageIcon img2 = new ImageIcon("cardBack.jpg");
    Image image = img2.getImage();
    Image scaledImage = image.getScaledInstance(CARD_WIDTH, CARD_HEIGHT, Image.SCALE_FAST);
    img2.setImage(scaledImage);
    _cardBacks[crdBackPosition ++] = new Card (img2, _initX++, _initY++);
    //shuffle();
    JPanel setUpPanel = new JPanel();
    setPreferredSize(new Dimension(1000, 700));
    setBackground(Color.white);
    JButton newGameButton = new JButton("New Game");
    JButton exitButton = new JButton("Exit");
    exitButton.addActionListener(new ExitAction());
    newGameButton.addActionListener(new NewGameAction());
    this.add(newGameButton);
    this.add(exitButton);
    class ExitAction implements ActionListener
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    class NewGameAction implements ActionListener
    public void actionPerformed(ActionEvent e)
    shuffle();
    repaint();
    public void paintComponent(Graphics g)
    shuffle();
    JPanel drawAndDealPanel = new JPanel();
    super.paintComponent(g);
    setBackground(Color.white);
    g.drawRect(PILE_DISTANCE_FROM_LEFT, PILE_DISTANCE_FROM_TOP, CARD_WIDTH, CARD_HEIGHT);
    g.drawRect(SHOWCARD_DISTANCE_FROM_LEFT, SHOWCARD_DISTANCE_FROM_TOP, CARD_WIDTH, CARD_HEIGHT);
    for(int position1 = ACES_DISTANCE_FROM_LEFT; position1 <= ACES_MAXIMUM; position1 += ACES_DISTANCE_BETWEEN_CARDS)
    g.drawRect(position1, ACES_DISTANCE_FROM_TOP, CARD_WIDTH, CARD_HEIGHT);
    for(int position2 = PLAYCARDS_DISTANCE_FROM_LEFT; position2 <= PLAYCARDS_MAXIMUM; position2 += PLAYCARDS_DISTANCE_BETWEEN_COLUMNS)
    g.drawRect(position2, PLAYCARDS_DISTANCE_FROM_TOP, CARD_WIDTH, CARD_HEIGHT);
    int crd1 = 1;
    int column1 = 300;
    int fromTop1 = PLAYCARDS_DISTANCE_FROM_TOP;
    Card cf = _cardFronts[crd1];
    cf.image.paintIcon(this, g, column1, fromTop1);
    crd1 = 2;
    column1 = 300 + PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    for(int count = 0; count < 6; count ++)
    Card cb = _cardBacks[crd1];
    cb.image.paintIcon(this, g, column1, fromTop1);
    crd1 ++;
    column1 += PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    int crd2 = 8;
    int column2 = 387;
    int fromTop2 = fromTop1 + PLAYCARDS_DISTANCE_BETWEEN_ROWS_FACEDOWN;
    cf = _cardFronts[crd2];
    cf.image.paintIcon(this, g, column2, fromTop2);
    crd2 = 9;
    column2 = 387 + PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    for(int count = 0; count < 5; count ++)
    Card cb = _cardBacks[crd2];
    cb.image.paintIcon(this, g, column2, fromTop2);
    crd2 ++;
    column2 += PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    int crd3 = 14;
    int column3 = 474;
    int fromTop3 = fromTop2 + PLAYCARDS_DISTANCE_BETWEEN_ROWS_FACEDOWN;
    cf = _cardFronts[crd3];
    cf.image.paintIcon(this, g, column3, fromTop3);
    crd3 = 15;
    column3 = 474 + PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    for(int count = 0; count < 4; count ++)
    Card cb = _cardBacks[crd3];
    cb.image.paintIcon(this, g, column3, fromTop3);
    crd3 ++;
    column3 += PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    int crd4 = 19;
    int column4 = 561;
    int fromTop4 = fromTop3 + PLAYCARDS_DISTANCE_BETWEEN_ROWS_FACEDOWN;
    cf = _cardFronts[crd4];
    cf.image.paintIcon(this, g, column4, fromTop4);
    crd4 = 20;
    column4 = 561 + PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    for(int count = 0; count < 3; count ++)
    Card cb = _cardBacks[crd4];
    cb.image.paintIcon(this, g, column4, fromTop4);
    crd4 ++;
    column4 += PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    int crd5 = 23;
    int column5 = 648;
    int fromTop5 = fromTop4 + PLAYCARDS_DISTANCE_BETWEEN_ROWS_FACEDOWN;
    cf = _cardFronts[crd5];
    cf.image.paintIcon(this, g, column5, fromTop5);
    crd5 = 24;
    column5 = 648 + PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    for(int count = 0; count < 2; count ++)
    Card cb = _cardBacks[crd5];
    cb.image.paintIcon(this, g, column5, fromTop5);
    crd5 ++;
    column5 += PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    int crd6 = 26;
    int column6 = 735;
    int fromTop6 = fromTop5 + PLAYCARDS_DISTANCE_BETWEEN_ROWS_FACEDOWN;
    cf = _cardFronts[crd6];
    cf.image.paintIcon(this, g, column6, fromTop6);
    crd6 = 27;
    column6 = 735 + PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    for(int count = 0; count < 1; count ++)
    Card cb = _cardBacks[crd6];
    cb.image.paintIcon(this, g, column6, fromTop6);
    crd6 ++;
    column6 += PLAYCARDS_DISTANCE_BETWEEN_COLUMNS;
    int crd7 = 28;
    int column7 = 822;
    int fromTop7 = fromTop6 + PLAYCARDS_DISTANCE_BETWEEN_ROWS_FACEDOWN;
    cf = _cardFronts[crd7];
    cf.image.paintIcon(this, g, column7, fromTop7);
    for(int playCard = 29; playCard < 52; playCard ++)
    Card cb = _cardBacks[playCard];
    cb.image.paintIcon(this, g, PILE_DISTANCE_FROM_LEFT, PILE_DISTANCE_FROM_TOP);
    this.add(drawAndDealPanel);
    //shuffle
    public void shuffle()
    Random rgen = new Random();
    for (int i=0; i<52; i++)
    int randomPosition = rgen.nextInt(52);
    Card temp = _cardFronts;
    _cardFronts = _cardFronts[randomPosition];
    _cardFronts[randomPosition] = temp;
    class Card
    ImageIcon image;
    int x;
    int y;
    public Card(ImageIcon image, int x, int y)
    this.image = image;
    this.x = x;
    this.y = y;
    }

    Please don't crosspost. It cuts down on the effectiveness of responses, leads to people wasting their time answering what others have already answered, makes for difficult discussion, and is generally just annoying and bad form.
    P.S. Repost your CODE, not a new thread....
    &#167;

  • Using JPanel with JFrame

    I am using a JFrame to encapsulate my program. I want to have a JPanel inside my JFrame to handle all of my 2d displaying (like fillRect() etc...). I used forte to set this up but I am having problems dispaying on the JPanel. Here is my code:
    here is how I call the function from the main .java file
    I dubuged this and know it works (proof will come later)
    private void Start_ButtonActionPerformed(java.awt.event.ActionEvent evt)
    myDisplay.draw();
    here is my entire JPanel class
    import java.awt.*;
    import javax.swing.*;
    public class Display extends javax.swing.JPanel
    public Display() {
    initComponents();
    public void paintComponent(Graphics g )
    System.out.println("1");
    super.paintComponent(g);
    g.setColor(Color.black);
    g.fillOval(50,10,60,60);
    public void draw()
    System.out.println("1");
    this.repaint(); //i also tried repaint() but it didn't work either
    System.out.println("2");
    private void initComponents()
    setLayout(new java.awt.BorderLayout());
    when I press the start button, 1 and 2 are displayed but 3 isn't. For some reason the repaint() function is not telling the paintComponent function to work. Any help is appreciated.
    Thanks,
    Every_man

    Every_man,
    After doing the super.paintComponent(g); you must use Graphics2D. So you next line should cast your graphics object to a graphics 2D object, like this. Graphics2D g2 = (Graphics2D)g;

  • JPanel without JFrame / JApplet / Window

    hello,
    I want to show a JPanel as an output without JFrame / JApplet / Window in background. My program ran successfully but without showing output.
    Actually I dont want title bar in an output, thats why i have selected JPanel.
    If anybody have idea about this plz tell me.
    Regards
    Nikhil

    This code works for me,
    import java.awt.Color;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class Forum extends JFrame {
         public Forum()
              setUndecorated(true);
              setBounds(100,100,400,400);
              JPanel pnl = new JPanel();
              JLabel lbl = new JLabel("THIS IS A LABEL IN A JPANEL IN AN UNDECORATED JFRAME");
              pnl.setBounds(0,0,400,300);
              pnl.setBackground(Color.CYAN);
              lbl.setBounds(0,0,200,100);
              pnl.add(lbl);
              getContentPane().add(pnl);
              setVisible(true);
         public static void main(String[] args) {
              Forum f = new Forum();
    }Just a quick and dirty example to show it's possible;
    ~Tim

Maybe you are looking for

  • Need information on 'Repeat Delta' process

    Deleted failed request from InfoCube 0PY_C02 Checked Data Mart Status from ODS ZPY_O50 for failed load. When attempting to push the data from the ODS to InfoCube get error message:      Last delta update is not yet completed      Therefore, no new de

  • Putting frame with buttons into a thread

    please help!!! i've got a thread: package aJile; import java.io.*; import java.net.*; public class SocketHandler extends Thread   private Socket socket;               // Socket used for messages    private int socketNr;   private byte[] inbuf;   priv

  • OS X refuses to shut down

    Anyone know how to shut down my imac? Aperture is frozen and won't stop. This prevents my system from shutting down. Anyone knows a solution?

  • Using BFILE pointer to point to xml data on ifs

    hai all, i need to create a table in which one of the columns is a BFILE pointer which points to XML/HTML/IMAGE content which is stored on iFS(internet file system).how do i go about it? is there any limit on the number of BFILE pointers columns that

  • Doubt in Validation

    Hi All, I need to validate the input given by the user in Table Maintenance Screen. So i used Table Maintenace -> Environment -> Events option to do that. In that , i configured such that whenever a new entry is created, my validation subroutine will