Determining if printing is going on in paint method

By looking at the source of the existing visual components, I have found out that JComponent.paintChildren uses getFlag(IS_PRINTING) to determine wether or not the current call to paint will paint to screen or to a printer.
The problem is that both getFlag and the constants it uses are declared as private in JComponent. This is why I am wondering why Sun chose to keep this information private to the JComponent class, while this information could be very useful in some situations.
Also, would there be any alternatives to determine wether or not printing is occuring from a paint method besides managing flags the same way JComponent does?
Thanks in advance.

I gave a try to your approach but it doesn't seem that the graphics object passed to the paint method during the printing process implements PrintGraphics. I'll keep trying stuff with that idea until some new input is given, but thanks for the idea, it sure could have worked out ;)

Similar Messages

  • Output determination and Printer determination for  both PO and GR

    Dear all,
    Can anyone please help me in congiguring the output determination and printer determination for  both PO and GR. please give me detailed configuration including the paths as i am stuck with the configuration.
    Thanks & Warm Regards
    Somashekar Anand

    hi Somashekar
    follow he steps
    Output of Purchase Order
    1. Condition Table
    SPRO > Material Management> Purchasing -> Message -> Output Control->Condition Tables->Define Condition Table for Purchase Order
    Select:
    Purchasing Doc. Type,
    Purch. Organization,
    Vendor
    2. Access Sequences
    SPRO -> Material Management-> Purchasing -> Message -> Output Control->Access Sequences->Define Condition Table for Purchase Order
    3. Message Type
    SPRO -> Material Management-> Purchasing -> Message -> Output Control->Message Types->Define Message Type for Purchase Order
    *4. Message Determination Schemas*
    4.1. Message Determination Schemas
    SPRO -> Material Management-> Purchasing -> Message -> Output Control->Message Schema->Define Message Schema for Purchase Order-> Maintain Message Determination Schema
    4.2. Assign Schema to Purchase Order
    SPRO -> Material Management-> Purchasing -> Message -> Output Control->Message Schema->Define Message Schema for Purchase Order-> Assign Schema to Purchase Order
    5. Partner Roles per Message Type
    SPRO -> Material Management-> Purchasing -> Message -> Output Control-> Partner Roles per Message Type ->Define Partner Role for Purchase Order
    6. Condition Record
    Navigation Path: SAP Menu-> Logistics -> Material Management -> Purchasing-> Master data->Messages-> Purchase Order-> MN04-> Create
    Now you create PO (ME21N) and save it. Go to ME22N and print the PO by giving output type.
    Output of GR
    After setting table, access sequence and output type for GR,run MB02 transaction, enter material document number. Double click one line item and select messages. Separate screen will be opened to configure outputs. Give the required fields and save the document. Now Run MB90, you can take printout. Output Type: WE03 or WE01 or WE02
    Reward points if helpful
    Thanks and regards
    Ravikant Dewangan

  • I cannot print any websites; every time I press "print" it goes to "save the file as [xps]" instead. What's up?

    I cannot print any websites; every time I press "print" it goes to "save the file as [xps]" instead. What's up? I can print in Word without problem.

    Bless you, bless you, bless you. After months of living with this annoying problem and not being able to print out emails or websites it is, in a stroke, totally solved. Thank you! It works. It's a wonder and you're a winner!
    Paul

  • HT204023 How do I set up to print from my iPad directly to a wi-fi direct printer WITHOUT going through my household  wi-fi network/modem?

    How do I set up to print from my iPad directly to a "wi-fi direct" printer WITHOUT going through my household wi-fi network/modem? I want to get rid of my household internet service/modem and only use my iPad, but need to be able to print. Please help! Thank you!

    Depending on the printer, you may be able to connect/print by creating an ad-hoc (Wi-Fi direct with no router) connection. Check with your printer manufacturer to see if this is supported.
    There's a ton of info out there. You could google "ipad print ad-hoc" for some useful info. But the number one thing for you right now is to verify that your printer model supports an ad-hoc connection.

  • I want to buy an hp m1536 laserjet for my ipad printing, I believe the printer is not wireless but has sprint. Is the print job going through my wireless router and does that router need to support AirPrint.

    I want to buy an hp m1536 laserjet for my ipad printing, I believe the printer is not wireless but has sprint. Is the print job going through my wireless router and does that router need to support AirPrint.

    The following model is airprint compatible, is this the one you have?
    HP LaserJet Pro M1536dnf MFP
    If not the "dnf MFP" model, then no.
    The router needs to support the Bonjour protocol.  If not, the airprint won't work.

  • My wireless printer keeps going offline--how can I "stabilize" the connection"

    my wireless printer keeps going offline--how can I "stabilize" the connection?
    This question was solved.
    View Solution.

    Hello gerrie,
    What i would do is Power cycle the printer and the router as well
    -basically having them turned off for about 10-15 seconds
    -and then powering back the router back on wait for all the lights to turn on completely
    -and after that is back up and running i would turn the printer back on and re-establish the connection between the printer and the Wireless network
    I am an HP employee.
    __ if this Solution has helped Please Mark as Resolved and feel free to Provide a Kudos__

  • How to call paint() method during creating object

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    class SomeShape extends JPanel {
         protected static float width;
         protected BasicStroke line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
    class Oval extends SomeShape {
         Oval(float width) {
              this.width = width;
              line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
              repaint();
         public void paint(Graphics g) {
              Graphics2D pen = (Graphics2D)g;
              int i = 10;
              super.paint(g);
                   g.setColor(Color.blue);
                   g.drawOval(90, 0+i, 90, 90);
                   System.out.println("paint()");
    public class FinalVersionFactory {
        JFrame f = new JFrame();
        Container cp = f.getContentPane();
        float width = 0;
        SomeShape getShape() {
             return new Oval(width++); //I want to paint this oval when I call getShape() method
         public FinalVersionFactory() {
              f.setSize(400, 400);
    //          cp.add(new Oval()); without adding
              cp.addMouseListener(new MouseAdapter() {
                   public void mouseReleased(MouseEvent e) {
                        getShape();
              f.setVisible(true);
         public static void main(String[] args) { new FinalVersionFactory(); }
    }I need help. When I cliked on the JFrame nothing happened. I want to call paint() method and paint Oval when I create new Oval() object in getShape(). Can you correct my mistakes? I tried everything...Thank you.

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    class SomeShape extends JPanel {
         protected static float width;
         protected static BasicStroke line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
    class Oval extends SomeShape {
         static int x, y;
         Oval(float width, int x, int y) {
              this.width = width;
              this.x = x;
              this.y = y;
              line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
         public void paint(Graphics g) {
              Graphics2D pen = (Graphics2D)g;
                   g.setColor(Color.blue);
                   pen.setStroke(line);
                   g.drawOval(x, y, 90, 90);
                   System.out.println("Oval.paint()"+"x="+x+"y="+y);
    class Rect extends SomeShape {
         static int x, y;
         Rect(float width, int x, int y) {
              this.width = width;
              this.x = x;
              this.y = y;
              line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
         public void paint(Graphics g) {
              Graphics2D pen = (Graphics2D)g;
                   g.setColor(new Color(250, 20, 200, 255));      
                   pen.setStroke(line);
                   g.drawRect(x, y, 80, 80);
                   System.out.println("Rect.paint()"+"x="+x+"y="+y);
    public class FinalVersionFactory extends JFrame {
        Container cp = getContentPane();
        float width = 0;
        int x = 0;
        int y = 0;
            boolean rect = false;
        SomeShape getShape() {
             SomeShape s;
              if(rect) {
                   s = new Rect(width, x, y);
                   System.out.println("boolean="+rect);
              } else {
                   s = new Oval(width++, x, y);
                   System.out.println("boolean="+rect);
              System.out.println("!!!"+s); //print Oval or Rect OK
              return s; //return Oval or Rect OK
         public FinalVersionFactory() {
              setSize(400, 400);
              SomeShape shape = getShape();
              cp.add(shape); //First object which is add to Container(Oval or Rect), returned by getShape() method
              //will be paint all the time. Why? Whats wrong?
              cp.addMouseListener(new MouseAdapter() {
                   public void mouseReleased(MouseEvent e) {
                        x = e.getX();
                        y = e.getY();
                        rect = !rect;
                        getShape();
                        cp.repaint(); //getShape() return Oval or Rect object
                                      //but repaint() woks only for object which was added(line 67) as first
              setVisible(true);
         public static void main(String[] args) { new FinalVersionFactory(); }
    }I almost finish my program but I have last problem. I explained it in comment. Please look at it and correct my mistakes. I will be very greatful!!!
    PS: Do you thing that this program is good example of adoption Factory Pattern?

  • Passing Data to a Paint Method

    Total newbie here just learning the basics of Java on my own. Working a little application that will display a filled polygon which shows the correct heading of ship based on previously input Ship Heading, length and width. I have the application working fine to generate the 5 points, and then it will display correctly when I enter the points in the paint method by hand. Thing is I want to have the coords passed to the paint method. and am having some trouble doing this. All the examples I have seen show the points to be displayed already being declared in the paint method. Here is the Paint Method I have come up with based on examples I have seen. Still pretty new and trying to read through the APIs and other books, but haven't broken the code on understanding them.
    import java.awt.*;
    import javax.swing.*;
    public class DrawShip5
       public static void main(String[] a)
        JFrame f = new JFrame();
        f.setTitle("Ship Heading");
        f.setSize(700,700);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(new DrawShip2());
        f.setVisible(true);
       static class DrawShip2 extends JComponent
           static public void paintData(int [] finalCoordsArray )
        int finalBowACoordX = finalCoordsArray[0];
        int finalBowACoordY = finalCoordsArray[1];
        int finalPortMidACoordX = finalCoordsArray[2];
        int finalPortMidACoordY = finalCoordsArray[3];
        int finalPortSternACoordX = finalCoordsArray[4];
        int finalPortSternACoordY = finalCoordsArray[5];
        int finalStarSternACoordX = finalCoordsArray[6]; 
        int finalStarSternACoordY = finalCoordsArray[7]; 
        int finalStarMidACoordX = finalCoordsArray[8];
        int finalStarMidACoordY = finalCoordsArray[9];       
        public void paint(Graphics g )
             // Am sure my problem lies in here
            int finalBowACoordX = paintData.finalBowACoordX;
            int finalBowACoordY = paintData.finalBowACoordY;
            int finalPortMidACoordX = paintData.finalPortMidACoordX;
            int finalPortMidACoordY = paintData.finalPortMidACoordY;
            int finalPortSternACoordX = paintData.finalPortSternACoordX;
            int finalPortSternACoordY = paintData.finalPortSternACoordY;
            int finalStarSternACoordX = paintData.finalStarSternACoordX; 
            int finalStarSternACoordY = paintData.finalStarSternACoordY; 
            int finalStarMidACoordX = paintData.finalStarMidACoordX;
            int finalStarMidACoordY = paintData.finalStarMidACoordY;    
             g.setColor(Color.black);
             g.drawLine(350, 0, 350, 700);
             g.drawLine(0, 350, 700, 350);
             g.setColor(Color.blue);
             Polygon shipPic = new Polygon();
             shipPic.addPoint( finalBowACoordX, finalBowACoordY ); // Bow Coords
             shipPic.addPoint( finalPortMidACoordX, finalPortMidACoordY ); // Port Midship Coords
             shipPic.addPoint( finalPortSternACoordX, finalPortSternACoordY ); // Port Aft Coords
             shipPic.addPoint( finalStarSternACoordX, finalStarSternACoordY ); // Starboard Aft Coords
             shipPic.addPoint( finalStarMidACoordX, finalStarMidACoordY ); // Starboard Midship Coords
             g.fillPolygon( shipPic );
    } Thanks for any help

    Looks like I was typing as Malcom was responding....where would I add that bit of code?
    import java.awt.*;
    import javax.swing.*;
    public class DrawShip5
       public static void main(String[] a)
        JFrame f = new JFrame();
        f.setTitle("Ship Heading");
        f.setSize(700,700);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(new DrawShip2());
        f.setVisible(true);    
        // Place the code here? Get an error for the finalCoordsArray not recognized
       static class DrawShip2 extends JComponent
                private int finalBowACoordX;
             private int finalBowACoordY;
             private int finalPortMidACoordX;
             private int finalPortMidACoordY;
             private int finalPortSternACoordX;
             private int finalPortSternACoordY;
             private int finalStarSternACoordX; 
             private int finalStarSternACoordY; 
             private int finalStarMidACoordX;
             private int finalStarMidACoordY; 
              static public void setCoords(int [] finalCoordsArray)
                 int finalBowACoordX = finalCoordsArray[0];
                 int finalBowACoordY = finalCoordsArray[1];
                 int finalPortMidACoordX = finalCoordsArray[2];
                 int finalPortMidACoordY = finalCoordsArray[3];
                 int finalPortSternACoordX = finalCoordsArray[4];
                 int finalPortSternACoordY = finalCoordsArray[5];
                 int finalStarSternACoordX = finalCoordsArray[6]; 
                 int finalStarSternACoordY = finalCoordsArray[7]; 
                 int finalStarMidACoordX = finalCoordsArray[8];
                 int finalStarMidACoordY = finalCoordsArray[9];
              // Print final coords after array passed and parsed
                 System.out.println("Paint Final Bow Coords: (" + finalBowACoordX + ", " + finalBowACoordY + ")");
                 System.out.println("Paint Final Port Midship Coords: (" + finalPortMidACoordX + ", " + finalPortMidACoordY + ")");
                 System.out.println("Paint Final Port Stern Coords: (" + finalPortSternACoordX + ", " + finalPortSternACoordY + ")");
                 System.out.println("Paint Final Starboard Stern Coords: (" + finalStarSternACoordX + ", " + finalStarSternACoordY + ")");
                 System.out.println("Paint Final Starboard Midship Coords: (" + finalStarMidACoordX + ", " + finalStarMidACoordY + ")");
          public void paintComponent(Graphics g )
            g.setColor(Color.black);
             g.drawLine(350, 0, 350, 700);
             g.drawLine(0, 350, 700, 350);
             g.setColor(Color.blue);
             Polygon shipPic = new Polygon();
             shipPic.addPoint( finalBowACoordX, finalBowACoordY ); // Bow Coords
             shipPic.addPoint( finalPortMidACoordX, finalPortMidACoordY ); // Port Midship Coords
             shipPic.addPoint( finalPortSternACoordX, finalPortSternACoordY ); // Port Aft Coords
             shipPic.addPoint( finalStarSternACoordX, finalStarSternACoordY ); // Starboard Aft Coords
             shipPic.addPoint( finalStarMidACoordX, finalStarMidACoordY ); // Starboard Midship Coords
             g.fillPolygon( shipPic );
    }Tried placing that code in a few spots and got errors.
    Appreciate the help, These are my first attempts at actually getting away from a single method program. Am getting it ...slowly, but I am getting it.

  • Over-riding the paint() method

    I want to create a custom button-rounded sides with straight top and bottom to be exact. I understand that you can use the Component class to create components, and over-ride the paint() method to create the actual button's appearance, but how do you do this? Also how do you go about creating an actionlistener for a component like my button idea? Any help will be appreciated!

    Since you are creating your own JButton you want to implement MouseListener so that you can detect the mouse up and mouse down events. If you are going to have a hover image then you want to implement MouseMotionListener as well. Here is an example:
    public class MyButton extends JComponent implement MouseListener, MouseMotionListener {
      private Vector listeners = new Vector();
      public MyButton() {
        addMouseListener(this);
        addMouseMotionListener(this);
      public void addActionListener(ActionListener al) {
        listeners.add(al);
      public void removeActionListener(ActionListener al) {
        listeners.remove(al);
      //add the overridden methods from MouseListener, MouseMotionListener
      public void paint(Graphics g) {
        //paint based on the events
    }This class will be notified when the mouse enters, exits, is clicked, etc. and you can set a state variable so that your paint routine knows what image to paint.
    Hopefully this will clear it up. Not sure how I can make it clearer.

  • Help with 2D Graphics - How do I send Variable data to paint method?

    I am working on a program that figures mortgage payments and an amortization schedule when a user inputs the principle, APR, and term length in years. After it figures all of those, I want to be able to display a chart that shows the principle and interest amounts for each year. My problem is, how do I get my loan information into my paint method so that I can draw a chart using that data? Any help would be greatly appreciated. The graph class in the code below is called after pressing a "Display Graph" button from my GUI.
    I'm pasting my code below. This does not include my main method or my GUI method. I can post those if necessary. Here is my code so far:
    import java.util.*;
    import java.lang.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.io.*;
    import java.lang.Math;
    public class Graph extends JFrame
         public Graph(double dCurrentBalance, double dMonthlyPmt, double dRate, int iTime)
              final double balance = dCurrentBalance;
              JFrame graphFrame;
              int iCounter = 0;
              int iPmtNumber = 0;
              double dCurrentInt = 0.0;
              double dCurrentPrinciple = 0.0;
              double dMPR = 0.0;
              int yCoordInt = 0;               //integer for Y coordinate for Interest
              int yCoordPrinciple = 0;     //integer for Y coordinate for Principle
              iTime *= 12;               //determine number of months for this loan
              iCounter = iTime;          //set loop counter to number of months for this loan
              dMPR = dRate/12;          //determine monthly periodic rate
              graphFrame = new JFrame ("mCalc Graph");
              graphFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              graphFrame.setSize(800,600);
              graphFrame.setResizable(false);
              // center graphFrame on the screen
         Dimension ScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
         Dimension FrameSize = graphFrame.getSize();
         if (FrameSize.height > ScreenSize.height)
         FrameSize.height = ScreenSize.height;
         if (FrameSize.width > ScreenSize.width)
         FrameSize.width = ScreenSize.width;
         graphFrame.setLocation((ScreenSize.width - FrameSize.width) / 2,
                   (ScreenSize.height - FrameSize.height) / 2);
              //Displays graphFrame
              Graphic graphicPane = new Graphic();
              graphFrame.add(graphicPane);
              graphFrame.setVisible(true);
              //This loops until all payments have been figured
              for (; iCounter > 0; )
         iPmtNumber++;
         dCurrentInt = dCurrentBalance * dMPR;
         dCurrentPrinciple = dMonthlyPmt - dCurrentInt;
         dCurrentBalance = dCurrentBalance - dCurrentPrinciple;
                   if (iPmtNumber%12 == 0)
    //           System.out.println("dCurrentBalance = " + dCurrentBalance);
    //                    System.out.println("Payment # = " + iPmtNumber);
    //                    System.out.println("dCurrentInt = " + dCurrentInt);
    //                    System.out.println("dCurrentPrinciple = " + dCurrentPrinciple);
         iCounter = iCounter-1;
              } //end for loop
         } //end Graph constructor
    /* This class needs to be personalized to include my own variable names,
    *     etc. I also need to find a way to bring in data from the Graph class.
         class Graphic extends JPanel
              public void paintComponent(Graphics comp)
                             int i; // Declare the variables used to generate the chart
    float xLoc = 50; // Location of the X Axis along Y
    float yLoc = 50; // Location of the Y Axis along X
    Line2D.Float LnA; //
    super.paintComponent(comp);
                   // Establish a tie between this subroutine and the Graphic
    Graphics2D comp2D = (Graphics2D) comp;
    // Cast the Graphics named comp to a Graphics2D as comp2D
    comp2D.setColor(Color.white);
    // Set the background color
    comp2D.fillRect(0,0,800,600);
    // Draw the X and Y axis
    comp2D.setColor(Color.black); // Set the pen color to black
    Line2D.Float YAxis = new Line2D.Float(50,50,50,getSize().height - 50); // Define the Y-Axis
    Line2D.Float XAxis = new Line2D.Float(50F,getSize().height - 50F, getSize().width -50F, getSize().height -50F); //Define the X-Axis
    comp2D.draw(YAxis); // Draw the Y-Axis
    comp2D.draw(XAxis); // Draw the X-Axis
    Font font = new Font("Dialog", Font.BOLD, 12); // Set the font for the Axis labels
    comp2D.setFont(font);
    float increment = 15;
    // Draw the line
    xLoc += increment;
    comp2D.setColor(Color.red);
    /* Need to find a way to bring in my own data to use for the
    * yLoc variables.
    for (i=1; i<=45; i++)
    { // Begin making the graph
    if (i < 30)
         yLoc += increment;
    } else {
         yLoc -= increment;
    // Scale the location to the graph height
    LnA = new Line2D.Float( xLoc, getSize().height - 50F , xLoc, yLoc); // Create the line
    comp2D.draw(LnA); // Draw the line
    xLoc += increment;
                             }//end for
                   }//end paintComponent
              } //end class Graphic
    } //end class Graph
    Any help would be GREATLY appreciated! Thanks.
    Message was edited by:
    russedl
    My email address iss [email protected] if you wish to reply privately. I can send my entire program code if that will help. Thanks!

    Hi Deca,
    You can use the CmdExecuteSync method of the DIAdem.TOCommand interface to set the value of a text channel. For example passing the string "CHT(1,1) := 'test'" as a parameter to the CmdExecuteSync method will set the 1st row of the 1st channel to "test". Please refer to the DIAdem help for more documentation on the CHT function.
    I hope this helps! Please post back if I wasn't clear enough in explaining how to do this or if you have any problems getting it to work.
    Regards,
    Sarah Miracle
    National Instruments

  • Multiple paint methods

    Hi
    I'm working on a draughts game and to make it a little nicer looking I've used graphics for the board squares.
    My paint method is double buffered so when a peice is dragged it lags a little because it has to buffer so many images. The only images I need to buffer are the ones that move i.e. the draughts.
    Is there a way to draw the squares in a separate paint method so they don't get buffered? Or is java limited to one paint method per class?

    It's going to lag no matter how many paint methods you use. (Thats even if there ARE other paint methods) If it's lagging because of how many images must be drawn, then perhaps you should write an algorithm that repaints only the areas that have changed. ie: Only repaint wherever the single peice is moved.
    -Adam

  • How is paint() method invoked?

    Hi
    I know this may be a silly question but I am not able to understand this concept. I have gone through some concepts of Graphics in Java and some example programs but I am not able to understand what invokes Paint(Graphics g) method. As I dont get this, I am not able to write a program where if I press a Draw button, it draws a line.
    I also went through the following link "http://java.sun.com/docs/books/tutorial/2d/overview/index.html" but I did not get my answer.
    Please help me.
    lakki

    Swing determines when a component needs to be repainted. It has a class called the RepaintManager which manages this. You can force the repainting of a component by using the repaint() method.
    You should never override the paint() method. Custom painting should be done by overriding the paintComponent() method in Swing. Read the Swing tutorial on "Custom Painting":
    http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html

  • Adding a JButton when there's a paint method

    I'm creating a game application, sort of like a maze, and I want to add buttons to the levelOne panel to be able to move around the maze. When I add the buttons to the panel they don't appear, I assume the paint method is the reason for this. here's my code, I have 3 files, ill post the user_interface, and the levels class, where the level is created and where i tried to add the button. I tried putting the buttons in a JOptionPane, but then my JMenu wouldn't work at the same time the OptionPane was opened. If anyone knows a way around this instead, please let me know. I also tried using a separate class with a paintComponent method in it, and then adding the button (saw on a forum, not sure if it was this one), but that didn't work either. Also, if there is a way just to simply have the user press the directional keys on the keyboard and have the program perform a certain function when certain keys are pressed, I'd like to know, as that would solve my whole problem. Thanks.
    //Libraries
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    public class User_Interface extends JFrame
    static Levels l = new Levels ();
    static Delay d = new Delay ();
    private Container contentPane = getContentPane ();
    private JPanel main, levelOne;
    private String level;
    private CardLayout cc = new CardLayout ();
    private GridBagConstraints gbc = new GridBagConstraints ();
    private JPanel c = new JPanel ();
    private String label = "MainMenu";
    public User_Interface ()
    //Generates the User-Interface
    super ("Trapped");
    main = new JPanel ();
    GridBagLayout gbl = new GridBagLayout ();
    main.setLayout (gbl);
    c.setLayout (cc);
    // set_gbc (gbc, 2, 2, 5, 5, GridBagConstraints.NONE);
    c.add (main, "Main Page");
    contentPane.add (c, BorderLayout.CENTER);
    cc.show (c, "Main Page");
    levelOne = new JPanel ();
    levelOne.setLayout (new GridBagLayout ());
    levelOne.setBackground (Color.black);
    c.add (levelOne, "LevelOne");
    JMenuBar menu = new JMenuBar ();
    JMenu file = new JMenu ("File");
    JMenu help = new JMenu ("Help");
    JMenuItem about = new JMenuItem ("About");
    JMenuItem mainmenu = new JMenuItem ("Main Menu");
    mainmenu.addActionListener (
    new ActionListener ()
    public void actionPerformed (ActionEvent event)
    cc.show (c, "Main Page");
    label = "MainMenu";
    JMenuItem newGame = new JMenuItem ("New Game");
    newGame.addActionListener (
    new ActionListener ()
    public void actionPerformed (ActionEvent event)
    l.xCord = 2;
    l.yCord = 2;
    l.xLoc = 140;
    l.yLoc = 140;
    JPanel entrance = new JPanel ();
    entrance.setLayout (new FlowLayout ());
    c.add (entrance, "Entrance");
    label = "Entrance";
    level = "ONE";
    cc.show (c, "Entrance");
    JMenuItem loadgame = new JMenuItem ("Load Game");
    JMenuItem savegame = new JMenuItem ("Save Game");
    JMenuItem exit = new JMenuItem ("Exit");
    exit.addActionListener (
    new ActionListener ()
    public void actionPerformed (ActionEvent event)
    JFrame frame = new JFrame ();
    frame.setLocation (10, 10);
    JOptionPane.showMessageDialog (frame, "Come Back Soon!", "TRAPPED", JOptionPane.INFORMATION_MESSAGE);
    System.exit (0);
    file.add (about);
    file.add (mainmenu);
    file.add (newGame);
    file.add (loadgame);
    file.add (savegame);
    file.add (exit);
    menu.add (file);
    menu.add (help);
    setJMenuBar (menu);
    //Sets the size of the container (columns by rows)
    setSize (750, 550);
    //Sets the location of the container
    setLocation (10, 10);
    //Sets the background colour to a dark blue colour
    main.setBackground (Color.black);
    //Makes the container visible
    setVisible (true);
    public void paint (Graphics g)
    super.paint (g);
    g.setColor (Color.white);
    if (label == "MainMenu")
    for (int x = 0 ; x <= 50 ; ++x)
    g.setColor (Color.white);
    g.setFont (new Font ("Arial", Font.BOLD, x));
    g.drawString ("T R A P P E D", 100, 125);
    d.delay (10);
    if (x != 50)
    g.setColor (Color.black);
    g.drawString ("T R A P P E D", 100, 125);
    if (label == "Entrance")
    l.Entrance ("ONE", g);
    label = "LevelOne";
    if (label == "LevelOne")
    l.LevelOne (g, levelOne, gbc);
    label = "";
    public static void main (String[] args)
    // calls the program
    User_Interface application = new User_Interface ();
    application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    } //End of Main Method
    //Libraries
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Levels extends Objects
    private JFrame frame = new JFrame ();
    //Sets location, size, and visiblity to the frame where the JOptionPane
    //will be placed
    frame.setLocation (600, 600);
    frame.setSize (1, 1);
    frame.setVisible (false);
    public int xCord = 2;
    public int yCord = 2;
    public void LevelOne (Graphics g, JPanel one, GridBagConstraints gbc)
    ***Trying to add the button, doesn't appear. Tried adding to the container, and any JPanel i had created***
    JButton button1 = new JButton ("TEST");
    one.add (button1);
    g.setColor (Color.white);
    g.fillRect (500, 100, 200, 300);
    g.setColor (Color.black);
    g.drawRect (500, 100, 200, 300);
    g.setFont (new Font ("Verdana", Font.BOLD, 25));
    g.setColor (Color.black);
    g.drawString ("LEVEL ONE", 525, 80);
    //ROW ONE
    counter = -80;
    counter2 = 200;
    for (int a = 1 ; a <= 7 ; ++a)
    if (xCord < a && yCord == 0)
    g.setColor (darkGray);
    g.fillRect (xLoc + counter, yLoc - 80, 40, 40);
    g.setColor (Color.black);
    g.drawRect (xLoc + counter, yLoc - 80, 40, 40);
    if (xCord > a - 1 && yCord == 0)
    g.setColor (darkGray);
    g.fillRect (xLoc + counter2, yLoc - 80, 40, 40);
    g.setColor (Color.black);
    g.drawRect (xLoc + counter2, yLoc - 80, 40, 40);
    counter += 40;
    counter2 += 40;
    *****Theres 9 more rows, just edited out to save space****
    int y = 100;
    int x = 100;
    for (int a = 0 ; a < 20 ; ++a)
    g.setColor (Color.white);
    g.fillRoundRect (x, y, 40, 40, 5, 5);
    g.setColor (Color.black);
    g.drawRoundRect (x, y, 40, 40, 5, 5);
    y += 40;
    if (a == 9)
    x += 320;
    y = 100;
    x = 140;
    y = 100;
    for (int a = 0 ; a < 14 ; ++a)
    g.setColor (Color.white);
    g.fillRoundRect (x, y, 40, 40, 5, 5);
    g.setColor (Color.black);
    g.drawRoundRect (x, y, 40, 40, 5, 5);
    x += 40;
    if (a == 6)
    x = 140;
    y += 360;
    g.setColor (Color.black);
    g.drawRect (100, 100, 360, 400);
    ImageIcon[] images = new ImageIcon [4];
    images [0] = new ImageIcon ("arrow_left.gif");
    images [1] = new ImageIcon ("arrow_up.gif");
    images [2] = new ImageIcon ("arrow_down.gif");
    images [3] = new ImageIcon ("arrow_right.gif");
    int direction = -1;
    *****This is where I tried to have the OptionPane show the directional buttons******
    //frame.setVisible (true);
    // direction = JOptionPane.showOptionDialog (frame, "Choose Your Path:", "Trapped", JOptionPane.YES_NO_CANCEL_OPTION,
    // JOptionPane.QUESTION_MESSAGE,
    // null,
    // images,
    // images [3]);
    // if (direction == 0)
    // if (xCord - 1 > 0)
    // xCord -= 1;
    // xLoc += 40;
    // if (direction == 1)
    // if (yCord - 1 > 0)
    // yCord -= 1;
    // yLoc += 40;
    // if (direction == 2)
    // if (yCord + 1 < 9)
    // yCord += 1;
    // yLoc -= 40;
    // if (direction == 3)
    // if (xCord + 1 < 13)
    // xCord += 1;
    // xLoc -= 40;
    //LevelOne (g, one, gbc);
    }

    i tried adding a keylistener, that didn't work too well, i had tried to add it to a button and a textarea which i added to the 'one' frame, it didn't show up, and it didn't work. How would i go about changing the paint method so that it doesn't contain any logic? That's the only way I could think of getting the program to move forward in the game. Thanks.
    //Libraries
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    public class User_Interface extends JFrame
        static Levels l = new Levels ();
        static Delay d = new Delay ();
        private Container contentPane = getContentPane ();
        private JPanel main, levelOne;
        private String level;
        private CardLayout cc = new CardLayout ();
        private GridBagConstraints gbc = new GridBagConstraints ();
        private JPanel c = new JPanel ();
        private String label = "MainMenu";
        public User_Interface ()
            //Generates the User-Interface
            super ("Trapped");
            main = new JPanel ();
            GridBagLayout gbl = new GridBagLayout ();
            main.setLayout (gbl);
            c.setLayout (cc);
            // set_gbc (gbc, 2, 2, 5, 5, GridBagConstraints.NONE);
            c.add (main, "Main Page");
            contentPane.add (c, BorderLayout.CENTER);
            cc.show (c, "Main Page");
            levelOne = new JPanel ();
            levelOne.setLayout (new GridBagLayout ());
            levelOne.setBackground (Color.black);
            c.add (levelOne, "LevelOne");
            JMenuBar menu = new JMenuBar ();
            JMenu file = new JMenu ("File");
            JMenu help = new JMenu ("Help");
            JMenuItem about = new JMenuItem ("About");
            JMenuItem mainmenu = new JMenuItem ("Main Menu");
            mainmenu.addActionListener (
                    new ActionListener ()
                public void actionPerformed (ActionEvent event)
                    cc.show (c, "Main Page");
                    label = "MainMenu";
            JMenuItem newGame = new JMenuItem ("New Game");
            newGame.addActionListener (
                    new ActionListener ()
                public void actionPerformed (ActionEvent event)
                    l.xCord = 2;
                    l.yCord = 2;
                    l.xLoc = 140;
                    l.yLoc = 140;
                    JPanel entrance = new JPanel ();
                    entrance.setLayout (new FlowLayout ());
                    c.add (entrance, "Entrance");
                    label = "Entrance";
                    level = "ONE";
                    cc.show (c, "Entrance");
            JMenuItem loadgame = new JMenuItem ("Load Game");
            JMenuItem savegame = new JMenuItem ("Save Game");
            JMenuItem exit = new JMenuItem ("Exit");
            exit.addActionListener (
                    new ActionListener ()
                public void actionPerformed (ActionEvent event)
                    JFrame frame = new JFrame ();
                    frame.setLocation (10, 10);
                    JOptionPane.showMessageDialog (frame, "Come Back Soon!", "TRAPPED", JOptionPane.INFORMATION_MESSAGE);
                    System.exit (0);
            file.add (about);
            file.add (mainmenu);
            file.add (newGame);
            file.add (loadgame);
            file.add (savegame);
            file.add (exit);
            menu.add (file);
            menu.add (help);
            setJMenuBar (menu);
            //Sets the size of the container (columns by rows)
            setSize (750, 550);
            //Sets the location of the container
            setLocation (10, 10);
            //Sets the background colour to a dark blue colour
            main.setBackground (Color.black);
            //Makes the container visible
            setVisible (true);
        public void paint (Graphics g)
            super.paint (g);
            g.setColor (Color.white);
            if (label == "MainMenu")
                for (int x = 0 ; x <= 50 ; ++x)
                    g.setColor (Color.white);
                    g.setFont (new Font ("Arial", Font.BOLD, x));
                    g.drawString ("T    R    A    P    P    E    D", 100, 125);
                    d.delay (10);
                    if (x != 50)
                        g.setColor (Color.black);
                        g.drawString ("T    R    A    P    P    E    D", 100, 125);
            if (label == "Entrance")
                l.Entrance ("ONE", g);
                label = "LevelOne";
            if (label == "LevelOne")
                l.LevelOne (g, levelOne, gbc);
                label = "";
            //g.setColor (new Color
        public static void main (String[] args)
            // calls the program
            User_Interface application = new User_Interface ();
            application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        } //End of Main Method
    //Libraries
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.ActionMap;
    import javax.swing.plaf.*;
    public class Levels extends Objects
        implements KeyListener
        //static final String newline = System.getProperty ("line.separator");
        JButton button;
        private JFrame frame = new JFrame ();
            //Sets location, size, and visiblity to the frame where the JOptionPane
            //will be placed
            frame.setLocation (600, 600);
            frame.setSize (1, 1);
            frame.setVisible (false);
        JButton button1;
        public int xCord = 2;
        public int yCord = 2;
        public void LevelOne (Graphics g, JPanel one, GridBagConstraints gbc)
        //    button = new JButton ("TEST");
        //    ButtonHandler handler = new ButtonHandler ();
         //   button.addActionListener (handler);
          //  one.add (button);
            g.setColor (Color.white);
            g.fillRect (500, 100, 200, 300);
            g.setColor (Color.black);
            g.drawRect (500, 100, 200, 300);
            g.setFont (new Font ("Verdana", Font.BOLD, 25));
            g.setColor (Color.black);
            g.drawString ("LEVEL ONE", 525, 80);
            //ROW ONE
            counter = -80;
            counter2 = 200;
            for (int a = 1 ; a <= 7 ; ++a)
                if (xCord < a && yCord == 0)
                    g.setColor (darkGray);
                    g.fillRect (xLoc + counter, yLoc - 80, 40, 40);
                    g.setColor (Color.black);
                    g.drawRect (xLoc + counter, yLoc - 80, 40, 40);
                if (xCord > a - 1 && yCord == 0)
                    g.setColor (darkGray);
                    g.fillRect (xLoc + counter2, yLoc - 80, 40, 40);
                    g.setColor (Color.black);
                    g.drawRect (xLoc + counter2, yLoc - 80, 40, 40);
                counter += 40;
                counter2 += 40;
            int y = 100;
            int x = 100;
            for (int a = 0 ; a < 20 ; ++a)
                g.setColor (Color.white);
                g.fillRoundRect (x, y, 40, 40, 5, 5);
                g.setColor (Color.black);
                g.drawRoundRect (x, y, 40, 40, 5, 5);
                y += 40;
                if (a == 9)
                    x += 320;
                    y = 100;
            x = 140;
            y = 100;
            for (int a = 0 ; a < 14 ; ++a)
                g.setColor (Color.white);
                g.fillRoundRect (x, y, 40, 40, 5, 5);
                g.setColor (Color.black);
                g.drawRoundRect (x, y, 40, 40, 5, 5);
                x += 40;
                if (a == 6)
                    x = 140;
                    y += 360;
            g.setColor (Color.black);
            g.drawRect (100, 100, 360, 400);
            ImageIcon[] images = new ImageIcon [4];
            images [0] = new ImageIcon ("arrow_left.gif");
            images [1] = new ImageIcon ("arrow_up.gif");
            images [2] = new ImageIcon ("arrow_down.gif");
            images [3] = new ImageIcon ("arrow_right.gif");
            int direction = -1;
            //frame.setVisible (true);
            // direction = JOptionPane.showOptionDialog (frame, "Choose Your //\Path:", "Trapped", JOptionPane.YES_NO_CANCEL_OPTION,
            //         JOptionPane.QUESTION_MESSAGE,
            //         null,
            //         images,
            //         images [3]);
            // if (direction == 0)
            //     if (xCord - 1 > 0)
            //         xCord -= 1;
            //         xLoc += 40;
            // if (direction == 1)
            //     if (yCord - 1 > 0)
            //         yCord -= 1;
            //         yLoc += 40;
            // if (direction == 2)
            //     if (yCord + 1 < 9)
            //         yCord += 1;
            //         yLoc -= 40;
            // if (direction == 3)
            //     if (xCord + 1 < 13)
            //         xCord += 1;
            //         xLoc -= 40;
            one.addKeyListener (this);
            // one.add (button1);
            if (xCord == 1)
                LevelOne (g, one, gbc);
        /** Handle the key typed event from the text field. */
        public void keyTyped (KeyEvent e)
        /** Handle the key pressed event from the text field. */
        public void keyPressed (KeyEvent e)
            if (e.getSource () == "Up")
                JOptionPane.showMessageDialog (null, "Hi", "Hi", 0, null);
        /** Handle the key released event from the text field. */
        public void keyReleased (KeyEvent e)
            // displayInfo (e, "KEY RELEASED: ");
    }

  • I'd like to select print paper size with using AxAcroPDFLib method depend on user

    I'd like to select print paper size with using AxAcroPDFLib method depend on user
    request. Is it possible? in AxAcroPDFLib?
    Is there any method to select print paper size in the C# programming.
    Or if you know another method, please introduce how to use.
    Thank you for your cooperation always.

    I am pretty sure that you can only do this from JavaScript or from C/C++ APIs.

  • Paint() method in an entity class

    Hi,
    I am trying to draw 2 shapes in a Canvas, one rectangle and a circle.
    However, I have an entity class for both the rectangle and the circle, something like:
    public class MyRectangle
    private int width, height;
    public MyRectangle() { ... }
    pulbic getWidth() { return width; }
    pulbic getHeight() { return Height; }
    I do not want to draw these 2 shape in the paint() method of the Canvas, I want my Rectangle class and my Circle to have their own paint method to draw themselves into the canvas, is it possible?
    If it is possible, can you tell me roughly how to do it?
    Do I have to extend the Component class?
    Thanks in advance.
    SK

    Hi,
    I tried to do what you mentioned as the following, but I cant get the circle display on the screen, do you know why? Thanks
    public class Ball extends Component
    private static final int diameter = 15;
    private int xPosition = 10, yPosition = 10;
    public Ball()
    public int getX() { return xPosition; }
    public int getY() { return yPosition; }
    public int getDiameter() { return diameter; }
    public void paint(Graphics g)
         super.paint(g);
    Graphics2D graphics2D = (Graphics2D)g;
    graphics2D.fillOval(xPosition, yPosition, diameter, diameter);
    public class MyFrame extends JFrame
    public MyFrame()
    // Set up the main frame
    super("Test");
    setPreferredSize(new Dimension(400, 300));
    Container contentPane = getContentPane();
         Ball aBall = new Ball();
         JPanel myPanel = new JPanel();
         myPanel.setBackground(Color.white);
         myPanel.setBorder(BorderFactory.createLineBorder(Color.black));
         myPanel.setOpaque(true);
    myPanel.add(aBall);
         contentPane.add(myPanel, BorderLayout.CENTER);     
    pack();
    /** The main method */
    public static void main(String[] args)
         MyFrame myFrame = new MyFrame();
    myFrame.setVisible(true);
    }

Maybe you are looking for

  • HCM Event Manager is not visible in HRMS 9.1

    Hello Everyone, We are trying to access below : Set up HRMS > System Administration > HCM Event Manager but the HCM Event Manager is not visible to me.Also when I tried to access the objects in Application designer like HCM_EM_MONITOR component and o

  • Why my mozilla firefox cant open . and i had been uninstall and download and repeated 10 times already please show me a solution i cant do my work without it

    please give me advise . when i clean the ccleaner its said mozilla in progress like 'cant clean the mozilla cache still running' please give advise , im using firefox on internship program

  • Subscription Confusion

    Hello Ok yesterday I was confused because a lot of ondemand shows that should be FREE were suddenly showing up as £1.10 charge to watch them and after reading a few messages and the price change information in january which reduced all packages (Bron

  • Migrating to xdk10 from xdk9

    I don't know if this question had been answered before or not but we are migrating from xdk9 to xdk10 and encountering alot of xsl issues. i am using Altova xmlspy 2006 IDE to write xsl and it is validated and all but when I use the same xsl in the a

  • How to jam rogue APs

    Dear I have detected several rogue APs in my company, one is with no security key. We are using 4402 WLC, i tried to contain those rogue APs , after this it shows these APs as contained, but no effect on SSID, still anyone can use it. Can someone tel