Java app Graphics object help

Hey, how do I get a graphics object in a Java application? In an applet, the entire thing's a graphics object. I want to somehow draw stuff onto a JPanel or something of the like. How do I do this?!?!?

you need to overload the paint() method inherited from java.awt.Component , for example:
public void paint(Graphics g) {
  g.setColor(new java.awt.Color(0,0,255));
  g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
}note that this will totally override the look of the component. I'm not sure whether you can call super.paint() in the event that you are extending a panel or other non-abstract AWT or Swing component.
McF

Similar Messages

  • E63 JAVA Apps Problem

    I updated the E63 firmware to the latest version (v410). But after that, the existing some of my previously installed JAVA apps are no longer showing in Installations (although they are shown as installed in App Manager). And the JAVA apps which are shown, cannot be launched. That is, I click on them but nothing happens. Also I cannot uninstall any JAVA apps and also cannot install any JAVA apps. PLEASE HELP!

    Sometime I've had .sis installers hang at the start of installation, but a reboot always fixed the problem.  If rebooting your phone and/or disabling any antivirus/security software you may have installed doesn't help, then I'm afraid your only solution is to back up your data and perform a hard reset (*#7370# , default password 12345).  But before making work for yourself, download that program again or try installing a different Java program, just to make sure.  Good luck!

  • HTML Graphics object

    I am trying to get the java.awt.Graphics object for a URL. Here are my steps so far:
    1. Create JEditorPane (jep) and set the url on it.
    2. Graphics g = jep.getUI().getRootView(jep).getGraphics();
    However, I don't want to show the JEditorPane i.e. I want to simply give it a URL
    and have it create a Graphics object that I can paint elsewhere.
    This should be not that hard, right?
    Thanks a lot!!!

    humm no one know :(

  • NSService for Java App

    Hello,
    I have one Java app name "hill-resort", which registers for a service(NSService) on start. I have written JNI code to receive service request in my running java app. and in my app Info.plist, I have created Service entries. I am passing the file/folder name from mac context menu to my java app using JNI, till now it was working fine, but suddenly it has started giving error like:
    2014-07-19 18:52:56.807 hill-resort[2050:507] Failed to obtain a valid sandbox extension for item: [789514] of flavor: [public.file-url] from the pasteboard.
    2014-07-19 18:52:56.808 hill-resort[2050:507] Failed to get a sandbox extensions for itemIdentifier (789514).  The data for the sandbox extension was NULL
    And it is taking 3 to 10 seconds to get a call in java from the service, earlier it was instantaneous.
    I have google around to find out how to fix it, but haven't find a workable solution for Java app.
    Please help, how to fix it!

    > This is a continuation of a previous issue I've been working on. This
    > falls into the realm of filters, so I thought I'd move it here.
    The same sysops cover all the BM forums, therefore it doesn't matter.
    > I have a
    > java app that needs to connect to the internet. It works fine when I
    > unload ipflt. Using filter debug, it seems as if packets are going out
    > correctly, but are being dropped coming back. I thought, that with dynamic
    > NAT, I wouldn't have to create an inbound exception. Am I off base with that?
    Is the exception you made STATEFUL? If it's not stateful the return
    packets will be dropped.
    Cat
    NSC Volunteer Sysop

  • How to pass Objects from Java App to JavaFX Application

    Hello,
    New to the JavaFX. I have a Java Swing Application. I am trying to use the TreeViewer in JavaFX since it seems to be a bit better to use and less confusing.
    Any help is appreciated.
    Thanks
    I have my Java app calling my treeviewer JavaFX as
    -- Java Application --
    public class EPMFrame extends JFrame {
    Customer _custObj
    private void categoryAction(ActionEvent e)   // method called by Toolbar
            ocsCategoryViewer ocsFX;    //javaFX treeviewer
            ocsFX = new ocsCategoryViewer();    // need to pass in the Customer Object to this Not seeing how to do it.
                                                  // tried ocsFX = new ocsCategoryViewer(_custObj) ;    nothing happened even when set this as a string with a value
    public class ocsCategoryViewer extends Application {
    String _customer;
    @Override
        public void start(Stage primaryStage) {
         TreeView <String> ocsTree;
         TreeItem <String> root , subcat;
      TreeItem <String> root = new TreeItem <String> ("/");
            root.setExpanded(true);
             ocsTree = new TreeView <String> (root);
             buildTree();     // this uses the Customer Object.
            StackPane stkp_root = new StackPane();
            stkp_root.getChildren().add(btn);
            stkp_root.getChildren().add(ocsTree);
            Scene scene = new Scene(stkp_root, 300, 250);
            primaryStage.setTitle("Tree Category Viewer");
            primaryStage.setScene(scene);
            primaryStage.show();
        public static void main(String[] args) {
            _customer = args[0];      // temporarily trying to pass in string.
            launch(args);

    JavaFX and Swing integration is documented by Oracle - make sure you understand that before doing further development.
    What are you really trying to do?  The answer to your question depends on the approach you are taking (which I can't really work out from your question).  You will be doing one of:
    1. Run your Swing application and your JavaFX application as different processes and communicate between them.
    This is the case if you have both a Swing application with a main which you launch (e.g. java MySwingApp) and JavaFX application which extends application which you launch independently (e.g. java MyJavaFXApp).
    You will need to do something like open a client/server network socket between the applications and send the data between them.
    2. Run a Swing application with embedded JavaFX components.
    So you just run java MySwingApp.
    You use a JFXPanel, which is "a component to embed JavaFX content into Swing applications."
    3. Run a Java application with embedded Swing components.
    So you just run java MyJavaFXApp.
    You use a SwingNode, which is "used to embed a Swing content into a JavaFX application".
    My recommendation is:
    a. Don't use approach number one and have separate apps written in Swing and Java - that would be pretty complicated and unwarranted for almost all applications.
    b. Don't mix the two toolkits unless you really need to.  An example of a real need is that you have a huge swing app based upon the NetBeans platform and you want to embed a couple of JavaFX graphs in there.  But if your application is only pretty small (e.g., it took less than a month to write), just choose one toolkit or the other and implement your application entirely in that toolkit.  If your entire application is in Swing and you are just using JavaFX because you think its TreeView is easier to program, don't do that; either learn how to use Swing's tree control and use that or rewrite your entire application in JavaFX.  Reasons for my suggestion are listed here: JavaFX Tip 9: Do Not Mix Swing / JavaFX
    c. If you do need to mix the two toolkits, the answer of which approach to use will be obvious.  If you have a huge Swing app and want to embed one or two JavaFX components in it, then use JFXPanel.  If you have a huge JavaFX app and want to embed one or two Swing components in it, use a SwingNode.  Once you do start mixing the two toolkits be very careful about thread processing, which you are almost certain screw up at least during development, no matter how an experienced a developer you are.  Also sharing the data between the Swing and JavaFX components will be trivial as you are now running everything in the same application within the virtual machine and it is all just Java so you can just pass data around as parameters to constructors and method calls, the same way you usually do in a Java program, you can even use static classes and data references to share data but usually a dependency injection framework is better if you are going to do that - personally I'd just stick to simply passing data through method calls.

  • Help with first java app!

    Hello all. I'm very new to java, and I'm trying to create my first GUI app. The idea behind this app is for the user to enter number of hours worked and the rate of pay, and then it will mutliply them together and give you the result.
    I have my main class which sets up the frame then calls my panel class
    Inside my panel class I have two panels, one for the twi input textfields (hours and rate of pay) and one panel for the button and the result text field.
    I cannot figure out how to do get the value of both text fields and mutliply them together when the botton is clicked. Here's my code:
    import javax.swing.*;
    public class FirstProject
         public static void main (String[] args)
              //Sets up the frame
              JFrame frame = new JFrame ("My first Java app");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(300, 200); frame.setVisible(true);
              //Foreground panel class
              foreground fg = new foreground();
              //Add stuff
              frame.getContentPane().add(fg);
              frame.setVisible(true);
              frame.pack();
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.xml.bind.Marshaller.Listener;
    public class foreground extends JPanel implements ActionListener
         public foreground()
              //Setup the layout
              setLayout (new BoxLayout (this, BoxLayout.Y_AXIS));
              //Setup input panel
              JPanel input = new JPanel();
              input.setBackground(Color.white);
              input.setBorder(BorderFactory.createLineBorder(Color.black, 1));
              //Setup output panel
              JPanel output = new JPanel();
              output.setBackground(Color.white);
              output.setBorder(BorderFactory.createLineBorder(Color.black, 1));
              //Add main media
              add(input);
              add(output);
              //--**INPUT BOX**--\\
              //Setup the hours label
              JLabel hour = new JLabel("Number of hours worked: ");
              //Setup the rate of pay label
              JLabel pay = new JLabel("Enter your rate of pay: ");
              //Setup the rate of pay text field
              TextField paytext = new TextField("20", 3);
              //Setup the hour text field
              TextField hrtext = new TextField("40", 0);
              //Add objects for input
              input.add(hour);
              input.add(hrtext);
              input.add(pay);
              input.add(paytext);
              //--**OUTPUT BOX**--\\          
              //Set up objects in output panel
              JButton calculate = new JButton("Calculate!");
              calculate.addActionListener(this);
              calculate.setActionCommand("Calculate");
              //Add calculate text field
              TextField calculatetext = new TextField(2);
              //Add objects for output
              output.add(calculate);
              output.add(calculatetext);
    }Thanks in advance!!
    P.S. I'm using eclispe btw.

    Your problem is related to your ActionListener.
    public class foreground extends JPanel implements ActionListener
    calculate.addActionListener(this);You have it set up so the Foreground panel is listening to the calculate button's clicks, but it's not doing anything with the clicks.
    I would strongly suggest dropping the "implements ActionListener" bit and implementing a separate ActionListener, like so:
      JButton calculate = new JButton("Calculate!");
      ActionListener buttonListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          // do whatever you want with the
          // paytext.getText ...
          // hrtext.getText ...
      calculate.addActionListener(buttonListener);
      // and you don't need this:  calculate.setActionCommand("Calculate");rh

  • Problem running my Java apps in my LG phone. Please help!

    Hi all!!
    I am quite new to the world of J2me, altough I've been coding Java for quite a few years now.
    Recently I bought a LG u 8120 phone with Java-support so I decided it was time to step into the mobile Java-world.
    Now I have written my first small app, a simple timer application which my phone (strangely enough) does not already have.
    So what happens is this : I create my app on my PC and package it with the WTK into a jar -file and a jad-file which i transfer to the phone.
    After this I can see the name of my app in the list of available programs in the phone. But when I try to run it: Nothing. The Java logo shows up for a few seconds and then I am tossed back to the menu.
    I have thought of the following as possible problems:
    1. the 8120 does not support MIDP2.0
    2. I am doing something wrong transfering the files
    3. I have missed out on one or several necessary steps in the process
    Anyone who have developed Java apps for LG phones who can give me some hints?
    I've used the Sun J2ME Wireless Toolkit 2.2 with MIDP2.0 and CLDC1.1 .
    The apps works fine in the emulator. The problem starts when I want to run it in the phone. The phone I've tried is an LG u8120. LG apparently does not want to make life easy for its customers, so there is no support for transfering Java apps in the vendor-supplied software. I suppose that's because they want you to only download stuff from their site. However, after surfing around on some discussion forums for a while I found a program called G-thing which can be used to upload Java apps to LG-phones via USB.
    Any help is very appreciated!
    Thanks,
    Sarah

    Thanks,
    I have tried this and ruled out some of the possible causes.
    When I added some more exception handling, I could see that a "java.lang.IllegalArguenException" is thrown.
    When I ran the AudioDemo package that came with WTK2.2 I noticed that the examples that uses WAV-files do not work while the rest works fine.
    My new theory is now that the u8120 does not support the WAV-format, so I will try with an mp3 instead and see what happens.
    Anyone who knows if LG-phones support WAV-format?
    /Sarah

  • Multithreaded Java app calling C via JNI...need help!

    I have a multithreaded Java app making a JNI call into some C code. It is a high speed imaging algorithm that I simply can't/don't want to do in Java. I am very new to JNI and I am hoping to get some expert advice on how to solve this issue. Basically, I need a seperate JNI session (if that is such a thing) per thread. In other words, I need to essentially keep state of each JNI call as it pertains to the current thread.
    The 2 ideas I have thought about are:
    1. Have the native code pass the data back into java, and have the java object hold it. Then, when subsequent native calls are made, you pass the data as a paramter of the native method.
    (This can be painful as it a lot of complicated and/or a lot of data.)
    2. Define some sort of a structure to hold each instance of the data on the C side, returning to java a lookup key. Subsequent native calls include the key as a paramter, and the data is looked up. ( a quick example of this would be nice).
    I would appreciate any information/expereince/pains with this one.
    Thanks!

    2. Define some sort of a structure to hold each instance of the data on the C side, returning to java a lookup key. Subsequent native calls include the key as a paramter, and the data is looked up. ( a quick example of this would be nice).The lookup key, or a simple "pointer", can be returned to Java as a plain old "int" or "long" (I don't know what is the size of the pointers in your platform, if 32 or 64-bit). So you can return a "long", that can be treated by Java programs as an "opaque handle" (a pompous name for things that can't be handled adequately at the "client" side).
    I assume that C/C++ allocates the memory and it remains "fixed" (untouched by garbage collection) between calls. So a real C pointer can be used in such case. If you have some smarter scheme of allocating things in your program, return another kind of lookup key (for instance, if you allocate things in fixed-size C arrays, you can return the index of the C object in the array instead of returning a plain pointer.

  • Need help getting this Java app to work on Mac OS X

    Aloha all,
    I am testing this new Java app that was built that is based on th Axis and Allies strategy gaming engine. On the PC the author wrote a .bat file to launch the app and the JVM. But when I try and enter the arguments on the Mac OS X via the terminal window I get the Usage/Options argument options back. The ,bat file goes as follows:
    java -Xincgc -classpath ../classes;../lib/crimson.jar;../lib/jaxp.jar games.strategy.engine.framework.GameRunner
    It looks to me as if OS X if having problems with -Xincgc argument. I checked to see if I needed to download the JVM, but according to Apple it is already built in. Is there another way to enter the arguments to get this app to launch?
    Maui Duck

    Does OS X use ';' as a separator like windows, or does it use ':' like UNIX. that might be the problem.

  • Java 2D graphics help

    Hi, i need 2 files, Index class file(JFrame) and a Draw.class file
    Basically, i have a button in the index jframe form, and when i clicked on the button, there will be a JPanel/ Applet pop up, with a circle in it. can any1 write me some sample codes? a simple one will do. Thanks

    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.BasicStroke;
    import java.awt.GradientPaint;
    import java.awt.TexturePaint;
    import java.awt.Rectangle;
    import java.awt.Graphics2D;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Rectangle2D;
    import java.awt.geom.RoundRectangle2D;
    import java.awt.geom.Arc2D;
    import java.awt.geom.Line2D;
    import java.awt.image.BufferedImage;
    import javax.swing.JPanel;
    public class ShapesJPanel extends JPanel
       // draw shapes with Java 2D API
       public void paintComponent( Graphics g )
          super.paintComponent( g ); // call superclass's paintComponent
          Graphics2D g2d = ( Graphics2D ) g; // cast g to Graphics2D
          // draw 2D ellipse filled with a blue-yellow gradient
          g2d.setPaint( new GradientPaint( 5, 30, Color.BLUE, 35, 100,
             Color.YELLOW, true ) ); 
          g2d.fill( new Ellipse2D.Double( 5, 30, 65, 100 ) );
          // draw 2D rectangle in red
          g2d.setPaint( Color.RED );                 
          g2d.setStroke( new BasicStroke( 10.0f ) );
          g2d.draw( new Rectangle2D.Double( 80, 30, 65, 100 ) );
          // draw 2D rounded rectangle with a buffered background
          BufferedImage buffImage = new BufferedImage( 10, 10,
             BufferedImage.TYPE_INT_RGB );
          // obtain Graphics2D from bufferImage and draw on it
          Graphics2D gg = buffImage.createGraphics();  
          gg.setColor( Color.YELLOW ); // draw in yellow
          gg.fillRect( 0, 0, 10, 10 ); // draw a filled rectangle
          gg.setColor( Color.BLACK );  // draw in black
          gg.drawRect( 1, 1, 6, 6 ); // draw a rectangle
          gg.setColor( Color.BLUE ); // draw in blue
          gg.fillRect( 1, 1, 3, 3 ); // draw a filled rectangle
          gg.setColor( Color.RED ); // draw in red
          gg.fillRect( 4, 4, 3, 3 ); // draw a filled rectangle
          // paint buffImage onto the JFrame
          g2d.setPaint( new TexturePaint( buffImage,
             new Rectangle( 10, 10 ) ) );
          g2d.fill(
             new RoundRectangle2D.Double( 155, 30, 75, 100, 50, 50 ) );
          // draw 2D pie-shaped arc in white
          g2d.setPaint( Color.WHITE );
          g2d.setStroke( new BasicStroke( 6.0f ) );
          g2d.draw(
             new Arc2D.Double( 240, 30, 75, 100, 0, 270, Arc2D.PIE ) );
          // draw 2D lines in green and yellow
          g2d.setPaint( Color.GREEN );
          g2d.draw( new Line2D.Double( 395, 30, 320, 150 ) );
          // draw 2D line using stroke
          float dashes[] = { 10 }; // specify dash pattern
          g2d.setPaint( Color.YELLOW );   
          g2d.setStroke( new BasicStroke( 4, BasicStroke.CAP_ROUND,
             BasicStroke.JOIN_ROUND, 10, dashes, 0 ) );
          g2d.draw( new Line2D.Double( 320, 30, 395, 150 ) );
       } // end method paintComponent
    } // end class ShapesJPanelbasically.. when i click on a button in the index class file, it will call this class file, i do not know to code to call this class file.
    Edited by: slaydragon on Nov 11, 2007 10:55 AM

  • How to change the SQL-Query in (Report in ReportViewer) by running Java App

    Hello,
    Ich have an App which generates dynamicly SQL-Queries. By pressing a button it should generate a report with this generated Query.
    I´m using the ReportViewer.jar. Further is it possilbe to a extra parameters form app which are not in a DB?

    <p>There are a few ways that you can achieve this. If your SQL Queries have their filters modified (ie. WHERE clause) then this can be easily solved by adding report parameters to the Report filter. Search the in-product help for "Record Filter" and you should get a number of helpful resources returned.</p><p>Additionally, you can pass in java.sql.ResultSet objects with a populated recordset of the data you want to show in the report. We don&#39;t currently provide any tools to assist the creation of the code stubs for thick-client applications (like we do for JSP pages) however you can download a collection of thick-client sample code from here:</p><p><a href="http://support.businessobjects.com/communityCS/FilesAndUpdates/crxi_r2_jrc_desktop_samples.zip">http://support.businessobjects.com/communityCS/FilesAndUpdates/crxi_r2_jrc_desktop_samples.zip</a> </p><p>As I mentioned, this sample contains a collection of code snippets. The one in particular you will be interested in is titled "JRCResultsetDatasource". Hopefully, this will provide you with a few options. </p><p>Regards,<br />Sean Johnson (CR4E Product Manager) </p>

  • Trying to move a graphics object using buttons.

    Hello, im fairly new to GUI's. Anyway I have 1 class which makes my main JFrame, then I have another 2 classes, one to draw a lil square graphics component (which iwanna move around) which is placed in the center of my main frame and then another class to draw a Buttonpanel with my buttons on which is placed at the bottom of my main frame.
    I have then made an event handling class which implements ActionListner, I am confused at how I can get the graphics object moving, and where I need to place the updateGUI() method which the actionPerformed method calls from inside the event handling class.
    I am aware you can repaint() graphics and assume this would be used, does anyone have a good example of something simular being done or could post any help or code to aid me, thanks!

    Yeah.. here's an example of custom painting on a JPanel with a box. I used a mouse as it was easier for me to setup than a nice button panel on the side.
    Anyways... it should make it pretty clear how to get everything setup, just add a button panel on the side. and use it to move the box instead of the mouse.
    -Js
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.event.MouseInputAdapter;
    public class MoveBoxAroundExample extends JFrame
         private final static int SQUARE_EDGE_LENGTH = 40;
         private JPanel panel;
         private int xPos;
         private int yPos;
         public MoveBoxAroundExample()
              this.setSize(500,500);
              this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              this.setContentPane(getPanel());
              xPos = 250;
              yPos = 250;
              this.setVisible(true);     
         private JPanel getPanel()
              if(panel == null)
                   panel = new JPanel()
                        public void paintComponent(Graphics g)
                             super.paintComponent(g);
                             g.setColor(Color.RED);
                             g.fillRect(xPos-(SQUARE_EDGE_LENGTH/2), yPos-(SQUARE_EDGE_LENGTH/2), SQUARE_EDGE_LENGTH, SQUARE_EDGE_LENGTH);
                   MouseInputAdapter mia = new MouseInputAdapter()
                        public void mousePressed(MouseEvent e)
                            xPos = e.getX();
                            yPos = e.getY();
                            panel.repaint();
                        public void mouseDragged(MouseEvent e)
                            xPos = e.getX();
                            yPos = e.getY();
                            panel.repaint();
                   panel.addMouseListener(mia);
                   panel.addMouseMotionListener(mia);
              return panel;
         public static void main(String args[])
              new MoveBoxAroundExample();
    }

  • Trying to add a java.awt.Choice object to a JTable

    Hi
    I am creating an app. which uses a JTable as the front end, displaying string data in all cells except the first column, which I need to make java.awt.Choice objects (or equivalent) - users will click the cell, a list of job numbers will be displayed and they click the one they want.
    Every time I run the app instead of a drop down list of job numbers I get the text:
    java.awt.Choice[choice0,0,0,0x0,invalid,current=K5000]
    I am unsure how to proceed.
    Any and all help appreciated - for reference my code at present is:
    Choice jobNumber = new Choice();
    jobNumber.addItem("K5000");
    Object[][] dataValues = {
    {jobNumbers[0], "A job title", new Integer(0), new Integer(0), new Integer(8), new Integer(8), new Integer(4), new Integer(0), new Integer(0)},
    where the JTable constructor is passed this array
    regards
    David

    Don't mix Swing and AWT!! Have a look at the JTable tutorial on this site.
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#combobox

  • I cant get it to work! NullPointerExeption at first awt.Graphics Object

    I am writing a game with AWT having it as an applet. I intend NOT to use anything outside of Java 1.1
    For my Game i thought that i ATLEAST need the following classes:
    MainGame, Level, Unit.
    I Started writing Level. wrote a fewe methods for it such as
    drawGras(int grastype) And started to write MainGame to see if they would work together. it's is/is going to be my first Java application where i actually know what object orienting is... I have already wrote a game in Java but with out knowing what a class or what object orienting realy is(the game works rather good to) but this time i wanted to use object orienting but came up with problems =( if first posted in "New to Javaprogramming" but they couldn't help me and advice me here
    My previous post: http://forum.java.sun.com/thread.jsp?forum=54&thread=290558
    Here's my code:
    import java.awt.*;
    public class MainGame extends java.applet.Applet
         implements Runnable {
         Thread runner;
         Image ImgLevel, ImgUnit;
         public MainGame() {
              Level nr1 = new Level();
              nr1.init();
              nr1.setGround(300);
              nr1.drawGras(1);
              nr1.CalcGraphics();
              nr1.drawSky(1);
              Image ImgLevel = nr1.getLevelImage();
         public void paint(Graphics g) {
              g.drawImage(ImgLevel,0,0,this);
         public void update(Graphics g) {
              paint(g);
         public void init() {
              MainGame Game = new MainGame();
         public void stop() {
              runner = null;
              System.exit(1);
         public void start() {
              if(runner == null) {
                   runner = new Thread(this);
                   runner.start();
         void Pause(int time) {
             try {
                 Thread.sleep(time);
             } catch(InterruptedException e) {
               System.out.println(e.toString());
         public void run() {
              Thread thisThread = Thread.currentThread();
                   while(thisThread == runner) {
    class Level extends java.applet.Applet {
        Font BigText = new Font("Arial", Font.PLAIN, 36);
        Font Normal = new Font("Arial", Font.PLAIN, 14);
        Font Bold = new Font("Arial", Font.BOLD, 14);
        Graphics GrLevel;
        int pattern, sky, GroundtoWalk, Ground;
        Color BgColor = new Color(166,202,240);
        Color gras1 = new Color(0,255,0);
        Color gras2 = new Color(0,200,0);
        Color gras3 = new Color(0,100,0);
        Image ImgLevel;
        void setBgColor(int r, int g, int b) {
            BgColor = new Color(r,g,b);
        void CalcGraphics() {
            ImgLevel = createImage(800,600);
            GrLevel = ImgLevel.getGraphics();
        void setGround(int GrounD) {
            Ground = GrounD;
        void GroundToWalkADD(int addToGround) {
            GroundtoWalk = Ground + addToGround;
        void setGroundToWalk(int GrToWalk) {
            GroundtoWalk = GrToWalk;
        public void init() {
              System.out.println("Init 1"); // This was placed here when i was checking how far it got when debuging
              CalcGraphics();
              System.out.println("Init 2");
              drawGras(1);
              System.out.println("Init 3");
              repaint();
              System.out.println("Init 4");
        Image getLevelImage() {
            return ImgLevel;
        public void paint(Graphics g) {
              g.drawImage(ImgLevel,0,0,this);
        public void update(Graphics g) {
            paint(g);
        void drawGras(int pt) {
         GrLevel.setColor(BgColor);
         GrLevel.fillRect(0,0,800,600);
         switch(pt) {
              case 1:
                   GrLevel.setColor(gras1);
                   GrLevel.fillRect(0,GroundtoWalk,800,300);
                   GrLevel.setClip(0,GroundtoWalk,800,300);
                   for(int i = 0; 890>i;i=i+5) {
                        GrLevel.setColor(gras2);
                        GrLevel.drawLine(0+i,GroundtoWalk,-190+i,GroundtoWalk+300);
                   for(int i=950; 0<i; i=i-5) {
                        GrLevel.setColor(gras3);
                        GrLevel.drawLine(890-i,GroundtoWalk,1000-i,GroundtoWalk+300);
              break;
              case 2:
                   GrLevel.setColor(gras2);
                   GrLevel.fillRect(0,GroundtoWalk+5,800,300);
                   for(int i = 0; 890>i;i=i+5) {
                        GrLevel.setColor(gras3);
                        GrLevel.drawLine(0+i,GroundtoWalk,-190+i,GroundtoWalk+300);
                   for(int i=950; 0<i; i=i-5) {
                        GrLevel.setColor(gras1);
                        GrLevel.drawLine(890-i,GroundtoWalk,1000-i,GroundtoWalk+300);
              break;
              case 3:
                   GrLevel.setColor(gras3);
                   GrLevel.fillRect(0,GroundtoWalk+10,800,300);
                   for(int i = 0; 800>i; i=i+20) {
                        GrLevel.fillArc(0+i,GroundtoWalk,20,20,180,-180);
              break;
         pattern = pt;
        int getGrasPattern() {
             return pattern;
        void drawSky(int cl) {
                GrLevel.setColor(BgColor);
                GrLevel.fillRect(0,0,800,155);
                switch(cl) {
                    case 1:
                   for(int y = 0;y<7;y++) {
                   for(int x = 0;x<800;x=x+20) {
                                GrLevel.setColor(Color.white);
                                GrLevel.drawArc(x,y*20,20,20,180,180);
                                GrLevel.setColor(Color.red);
                                GrLevel.drawArc(x,y*20+4,20,20,180,180);
                                GrLevel.setColor(Color.yellow);
                                GrLevel.drawArc(x,y*20+2,20,20,180,180);
                                GrLevel.setColor(Color.green);
                                GrLevel.drawArc(x,y*20+8,20,20,180,180);
                                GrLevel.setColor(Color.blue);
                                GrLevel.drawArc(x,y*20+12,20,20,180,180);
                                GrLevel.setColor(Color.pink);
                                GrLevel.drawArc(x,y*20+16,20,20,180,180);
              break;
              case 2:
                        GrLevel.setColor(Color.gray);
              break;
         sky = cl;
         GrLevel.setFont(BigText);
         GrLevel.setColor(Color.black);
         GrLevel.fillRect(0,0,800,50);
         GrLevel.setColor(Color.white);
         GrLevel.drawString("Score Tabel - comming someday",((size().width)/2)-260, 40);
        int getSkyTyp() {
             return sky;
    }I tested running the code of class Level by puting it into Level.java and compiled it...ran it with appletviewer and it worked as it was intended to.
    But when i compiled it with MainGame... and in the HTML started MainGame.class,.....applet didn't intializeand i got the following error messege:
    Init 1
    java.lang.NullPointerException
            at Level.CalcGraphics(MainGame.java:84)
            at MainGame.<init>(MainGame.java:11)Line 82: void CalcGraphics() {
    Line 83: ImgLevel = createImage(800,600);
    Line 84: GrLevel = ImgLevel.getGraphics(); // The First awt.Graphics object
    Line 85: }
    Line 9:      public MainGame() {
    Line 10:     Level nr1 = new Level();
    Line 11:     nr1.CalcGraphics(); // calling the method above -> same error first awt.Graphics Object.
    If i change it os that "drawGras" comes first it's first awt.Graphics Line will show the same error
    Hope some one can and will help me

    As per the documentation of
    java.awt.Component.createImage(int,int):
    Creates an off-screen drawable image to be used for
    double buffering.
    Parameters:
    width - the specified width
    height - the specified height
    Returns:
    an off-screen drawable image, which can be used for
    double buffering. The return value may be null if the
    component is not displayable. This will always happen
    if GraphicsEnvironment.isHeadless() returns true.
    Since:
    JDK1.0 its not
    ImgLevel = createImage(800,600); that's making the problem but The first awt.Graphics Object in class Level, no mather which on it is =((
    >
    The key part is '...may be null if the component is
    not displayable.'
    You should put your graphics initialization code in
    start(), which will be called when your applet is
    ready to go. Before then, your applet is not
    displayable. (Also, remember to dispose() your
    graphics in your stop() method, if not sooner.)for the part writen above...I'll try to change it like you are saying.
    Thanx for your help!

  • Cannot resolve symbol java.awt.graphics

    // DrawRectangleDemo.java
    import java.awt.*;
    import java.lang.Object;
    import java.applet.Applet;
    public class DrawRectangleDemo extends Applet
         public void paint (Graphics g)
              // Get the height and width of the applet's drawing surface.
              int width = getSize ().width;
              int height = getSize ().height;
              int rectWidth = (width-50)/3;
              int rectHeight = (height-70)/2;
              int x = 5;
              int y = 5;
              g.drawRect (x, y, rectWidth, rectHeight);
              g.drawString ("drawRect", x, rectHeight + 30);
              x += rectWidth + 20;
              g.fillRect (x, y, rectWidth, rectHeight);
              // Calculate a border area with each side equal tp 25% of
              // the rectangle's width.
              int border = (int) (rectWidth * 0.25);
              // Clear 50% of the filled rectangle.
              g.clearRect (x + border, y + border,
                             rectWidth - 2 * border, rectHeight - 2 * border);
              g.drawString ("fillRect/clearRect", x, rectHeight + 30);
              x += rectWidth + 20;
              g.drawRoundRect (x, y, rectWidth, rectHeight, 15, 15);
              g.drawString ("drawRoundRect", x, rectHeight + 30);
              x=5;
              y += rectHeight + 40;
              g.setColor (Color.yellow);
              for (int i = 0; i < 4; i++)
                   g.draw3DRect (x + i * 2, y + i * 2,
                                       rectWidth - i * 4, rectHeight - i * 4, false);
              g.setColor (Color.black);
              g.drawString ("draw3DRect", x, y, + rectHeight + 25);
              x += rectWidth + 20;
              g.setColor (Color.yellow);
              g.fill3DRect (x, y, rectWidth, rectHeight, true);
              g.setColor (Color.black);
              g.drawString ("fill3DRect", x, y, + rectHeight + 25);
    Help me with this codes. I typed correctly but there still errors.
    --------------------Configuration: JDK version 1.3.1 <Default>--------------------
    D:\Program Files\Xinox Software\JCreator LE\MyProjects\DrawRectangleDemo.java:56: cannot resolve symbol
    symbol : method drawString (java.lang.String,int,int,int)
    location: class java.awt.Graphics
              g.drawString ("draw3DRect", x, y, + rectHeight + 25);
    ^
    D:\Program Files\Xinox Software\JCreator LE\MyProjects\DrawRectangleDemo.java:64: cannot resolve symbol
    symbol : method drawString (java.lang.String,int,int,int)
    location: class java.awt.Graphics
              g.drawString ("fill3DRect", x, y, + rectHeight + 25);
    ^
    2 errors
    Process completed.
    -------------------------------------------------------------------------------------------------------------------------------

    cannot resolve symbol
    symbol : method drawString (java.lang.String,int,int,int)
    This is telling you that you are trying to invoke the drawString() method with 4 parameters: String, int, int, int
    If you look at the API the drawString() method need 3 parameters: String, int, int - so you have an extra int
    location: class java.awt.Graphics
    g.drawString ("draw3DRect", x, y, + rectHeight + 25);
    Now is you look at your code you will find that you have 3 ',' in you method call. (I don't think you want the ',' after the y.

Maybe you are looking for

  • Database Link Creation and Acessing

    i want to talk between two oracle server. i decided to go for snapshot creation with periodical refresh. For which i am having two oracle server's with different ip address located inside our office setup. I have created a database link between two s

  • Arabic in XML Reports

    Hi, I have created a template of RTF format with which contains Arabic. It looks fine in the template but when I run the report through concurrent program it shows junk characters in the PDF output format. Please let me know what are the pre-requisit

  • Safari icon has disappeared on my new iPad.  Have to search for the app to open it.

    Received my new iPad yesterday. Safari icon does not appear on any screen. Have to search to open it

  • Solar chargers for 30G iPod Video

    Has anyone had any experience using any of the small solar chargers on the market that state they work with iPods. Most of them state that they are useable with iPods but I think they all are tested with the Nano or Mini only, and I'm wondering if th

  • How do I reinstall previous version of Pages, Numbers & Keynote

    How do I reinstall previous versions of Pages, Numbers and Keynote on my iPhone 4 using iOS 7.0.3. I use Time Machine. I want to keep old Data Files on the iPhone.