Static int

Hello guys, I have this public static int ID = 1; in my main class. However, i wanted to increment it at a different class. That was why i declared it to public. And i really need it to be static.
Here is the incrementation in a different class int x = Driver.ID;
Driver.ID = x++;The problem now is the ID in the Driver class does not increase. Please explain and tell me a solution. Thank you.

Just as a somewhat unrelated suggestion.
It would be better if you made a public method in your driver class to increment your ID variable(which by the way is named wrong, as its name suggests it is final).
This way you don't even have to declare it to public, you can leave it private or protected. It also makes your code overall much more easier to read and maintain. And last but certainly not least it makes your driver class more reuse friendly for any other classes that want to use it or increment ID in it, even in the future, without the necessity of removing any control you have over it.
Anytime you want to change data in another class your thoughts should be "what does that class have to let me do that?" If the answer is nothing but you authored both classes, then before doing it the way you did, you should consider adding a method to the class with the data to allow the answer to be present the next time you ask it.
Forcing data changes the way you did will eventually cause you headaches. So it is best to get into the right habbits now, rather than having to learn the hard way.
JSG

Similar Messages

  • Array static int help

    static int[]      insert(int x, int i, int[] a)
    insert takes an item x, an index i, and an array a, and returns a new array containing all the elements of a with one additional element, namely x, at position i.
    ok im trying to add 2 ints to the array?
    and i dont understand what im doing wrong this is what i tried and it says error bc it needs an int in the return.
    its suppose to do this
    a = new int[3]; a[0] = 5; a[1] = 2; a[2] = 7;
    a.length3
    b = insert(-42, 1, a); // -42 is passed into x and 1 is passed into i
    b.length4
    b[1]-42
    b[2]2
    this is what i have written that is wrong...
    public static int[] insert(int newZ, int newX, int[] a){
    int totals = 1;
    int z = newZ;
    int x = newX;
    for (int i = 0; i < a.length; i++){
    totals = (a[i]+ z + x);
    return totals;
    }

    Hi,
    This forum is exclusively for discussions related to Sun Java Studio Creator. Please post your question at :
    http://forum.java.sun.com/forum.jspa?forumID=54
    Thanks,
    RK.

  • What is public static int??

    hi everybody,
    I am attending data structure and alogrithms class ...i wanna know about all, so which book can I read to understand.
    Also in java what is the meaning of
    "public static int"....
    it have got "return" what is the meaning it ??
    best regards
    blazer

    Perhaps you should try the Java forums and not the Sun Ray forum :)

  • How to javadoc "public final static int"?

    How can we create "Field Summary" HTML document for "public final static int" variables?
    This question is probably same as the below question.
    http://forums.java.sun.com/thread.jsp?forum=41&thread=72832
    p.s.
    The below document indicates CENTER, NORTH, ...
    How an we achieve it to document "public final static" variables?
    http://java.sun.com/products/jdk/1.2/docs/api/index.html

    No, 1.3 does not have the static constant values exposed to the Doclet API,
    and so that information is not available to any doclets to place in the
    generated documentation.
    BTW, based on feedback from a developer, we changed the format from:
    public static final int NORTH = 0
    to
    public static final int NORTH
    See: Constant values
    where the "Constant values" link takes them to a summary page that
    lists all of the values. This helps discourage users from mistakenly
    seeing and using the value instead of the constant.
    -Doug Kramer
    Javadoc team

  • Code standard for get/set or static int?

    What is the standard for getting setting values in a class?
    ie.
    static int VALUE = 0;
    String[] values = new String[1];
    public void set(int in, String val){
         values[in] = val;
    public String get(int in){
         return values[in];
    }OR
    String val1;
    String val2;
    public String getVal1(){
         return val1;
    public void setVal1(String in){
         val1 = in;

    I would say the first is Very Bad, and the second is Good. In-between is Bad, which would be storing everything in a Map, where at least the values are named rather than having an anonymous number to identify them.
    With that said, where I work we actually have a class that uses the Bad solution that I outlined, but it's designed to be exposed publicly by subclasses using the standard getter/setter idiom, and the map itself is not used externally. So instead of being backed by variables, all the getters and setters are backed by a Map. It ends up being Not So Bad. :-)

  • Public static void vs. public static int

    hey java_experts,
    we're learning arrays and i was just wondering whats the difference between public static void vs. public static int

    hi i want to do java mail but i am new in this field
    so please suggest me how i have to get help for the
    java mailNext time start your own thread.
    Google for Java mail tutorial.

  • How to show staticly decleared int's in a JLabel

    hi
    how to show staticly decleared int's in a JLabel
    i have the following code but it doesnt seem to be working
           // Declear jlabel
            JLabel statuslabel = new JLabel(" X Axis : " + x + " Y Axis : + y ");
           // position of cursor
            public static int x;
            public static int y;
           

    nicchick wrote:
    um is there a easyer way to update int's inside a JLabel:)You need a MouseMotionListener
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.Point;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class CursorPositionInLabel
      private static final String BAD_LABEL = "Bad Label";
      private static final String GOOD_LABEL = "Good Label";
      private JPanel mainPanel = new JPanel();
      private Point cursorP = new Point();
      private JLabel badLabel = new JLabel(BAD_LABEL + ";  [" + cursorP.x + ", " + cursorP.y + "]"); // this guy never gets updated, & so never changes
      private JLabel goodLabel = new JLabel(GOOD_LABEL + ";  [" + cursorP.x + ", " + cursorP.y + "]");
      public CursorPositionInLabel()
        mainPanel.setPreferredSize(new Dimension(600, 600));
        mainPanel.setLayout(new GridLayout(1, 2));
        JPanel badPanel = new JPanel();
        badPanel.add(badLabel);
        JPanel goodPanel = new JPanel();
        goodPanel.add(goodLabel);
        mainPanel.add(badPanel);
        mainPanel.add(goodPanel);
        mainPanel.addMouseMotionListener(new MouseAdapter()
          // this is the event that gets tripped each time the mouse moves
          public void mouseMoved(MouseEvent e)
            // get the location of the mouse curse
            cursorP = e.getPoint();
            // and then update your JLabel with the coordinates
            goodLabel.setText(GOOD_LABEL + ";  [" + cursorP.x + ", " + cursorP.y + "]");
      public JPanel getMainPanel()
        return mainPanel;
      // create the JFrame in a thread-safe manner as the Sun tutorials tell us to do.
      private static void createAndShowUI()
        JFrame frame = new JFrame("CursorPositionInLabel");
        frame.getContentPane().add(new CursorPositionInLabel().getMainPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }Edited by: Encephalopathic on Jun 18, 2008 5:28 PM

  • ArrayList e .RangeCheck(int)line 546

    Hi guys I am working on this project
    in few word
    I have to draw different shape on a panel
    moreover when two similar shapes collide ( 2 circles ) they make a bigger circle
    when st change direction
    almost everything works
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Comparator;
    import java.util.Iterator;
    import javax.swing.JPanel;
    class ShapePanel extends JPanel implements ActionListener {
         private static final long serialVersionUID = 1L;
         public static ArrayList <Shape>shapes;
         private javax.swing.Timer animationTmr;
         int speed;
         PlaySound audioClip = new PlaySound();
         private float heigth;
         private float width;
         private int shape1;
         private int shape2;
         public ShapePanel() {
              shapes = new ArrayList<Shape>();
              animationTmr = new javax.swing.Timer(80, this); //interval, ActionListener
              animationTmr.start();
         public ArrayList<Shape> getShapes()
              return shapes;
         public void addSquare(int x, int y,int w,int h, int shapeType) {
              shapes.add(new Square(this,x, y,width, heigth, shapeType));
              repaint();
              System.out.println(shapes.size());
         public void addCircle(int x, int y,int w,int h, int shapeType) {
              shapes.add(new Circle(this, x, y,width, heigth, shapeType));
              repaint();
              System.out.println(shapes.size());
         public void addRectangle(int x, int y,int w,int h,  int shapeType) {
              shapes.add(new Rectangle(this, x, y,width, heigth, shapeType));
              repaint();
              System.out.println(shapes.size());
         public void addStar(int x, int y,int w,int h, int shapeType) {
              shapes.add(new Star(this, x, y,width, heigth, shapeType));
              repaint();
              System.out.println(shapes.size());
         public void paintComponent(Graphics g) { //called Whenever panel needs
              super.paintComponent(g); //re-displaying:
              Iterator<Shape> it = shapes.iterator(); //Iterate through Balls calling
              g.setColor(Menu.getColor());
              g.fillRect(0, 0, this.getWidth(), this.getHeight());
              while (it.hasNext()) { //each one's paint method
                   it.next().paint(g);
         public void actionPerformed(ActionEvent ev) {      
              //On timer tick,
              Iterator<Shape> it = shapes.iterator(); //Iterate through Balls calling
              while (it.hasNext()) { //each one's updatePos() method
                   it.next().updatePos();
              checkTypeCollision();
              handleCollision();
              repaint();
        private void checkTypeCollision()
              //we iterate through all the balls, checking for collision
              for(int i=0;i<shapes.size();i++)
                   for(int j=0;j<shapes.size();j++)
                             if(i!=j)
                                  if(collide(shapes.get(i), shapes.get(j)))
                                            shape1=shapes.get(i).shapeType;
                                            shape2=shapes.get(j).shapeType;
                                             if(shape1==shape2)
                                             /*     int     newX = (int) ((shapes.get(i).getCenterX() + (shapes.get(j).getCenterX()/2))/2);
                                                  int newY = (int) ((shapes.get(i).getCenterY() + (shapes.get(j).getCenterY() /2))/2);
                                                 float newWidth =   shapes.get(i).getWidth()+(shapes.get(j).getWidth()/2);
                                                 float newHeigth = shapes.get(i).getHeigth()+(shapes.get(j).getHeigth()/2);
                                                 int newShapeType = shapes.get(i).shapeType;
                                                       if(shapes.get(i).getShapeType()==1)
                                                            shapes.remove(j); //remove shape element at j
                                                            shapes.remove(i); //remove shape element at j
                                                            System.out.println("SIZE IS==="+     shapes.size());
                                                            System.out.println("newx====="+newX);
                                                            System.out.println("newy====="+newY);
                                                            System.out.println("newWidth====="+newWidth);
                                                            System.out.println("newx====="+newHeigth);
                                             //               shapes.add(new Rectangle(this,newX,newY,530,530,newShapeType));
                                                            System.out.println("SIZE IS==="+     shapes.size());
                                                       //     repaint();
                                                       if(shapes.get(i).getShapeType()==2)
                                                            shapes.remove(j); //remove shape element at j
                                                            shapes.remove(i); //remove shape element at j
                                                  //          shapes.add(new Circle(this,newX,newY,newWidth,newHeigth,newShapeType));
                                                       //     repaint();
                                                       if(shapes.get(i).getShapeType()==3)
                                                            shapes.remove(j); //remove shape element at j
                                                            shapes.remove(i); //remove shape element at j
                                                            shapes.add(new Square(this,newX,newY,newWidth,newHeigth,newShapeType));
                                                       if(shapes.get(i).getShapeType()==3)
                                                            shapes.remove(j); //remove shape element at j
                                                            shapes.remove(i); //remove shape element at j
                                                            //shapes.add(new Star(this,newX,newY,newWidth,newHeigth,newShapeType));
                                                       //     repaint();
         private void handleCollision()
              //we iterate through all the balls, checking for collision
              for(int i=0;i<shapes.size();i++)
                   for(int j=0;j<shapes.size();j++)
                             if(i!=j)
                                  if(collide(shapes.get(i), shapes.get(j)))
                                        shapes.get(i).hit(shapes.get(j));
                                       shapes.get(j).hit(shapes.get(i));                                   
         boolean collide(Shape b1, Shape b2)
              double wx=b1.getCenterX()-b2.getCenterX();
              double wy=b1.getCenterY()-b2.getCenterY();
              //we calculate the distance between the centers two
              //colliding balls (theorem of Pythagoras)
              double distance=Math.sqrt(wx*wx+wy*wy);
              if(distance<b1.shapeSize)     
                   audioClip.playRectangle();
                   return true;          
                   else return false;     
         public static int vectorSize()
              return shapes.size();
    }the drawing stops and
    i have this error after a while
    arrayList<e>.RangeCheck(int)line 546
    moreover it doesn t draw a bigger shape as i want with the line
    shapes.add(new Circle(this,newX,newY,newWidth,newHeigth,newShapeType));
                                                       help please the deadline is Tomorrow;

    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
         at java.util.ArrayList.RangeCheck(ArrayList.java:546)
         at java.util.ArrayList.get(ArrayList.java:321)
         at ShapePanel.checkTypeCollision(ShapePanel.java:156)
         at ShapePanel.actionPerformed(ShapePanel.java:77)
         at javax.swing.Timer.fireActionPerformed(Timer.java:271)
         at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    it doesn t compile because is part of a bigger project

  • Compilation error while calling static method from another class

    Hi,
    I am new to Java Programming. I have written two class files Dummy1 and Dummy2.java in the same package Test.
    In Dummy1.java I have declared a static final variable and a static method as you can see it below.
    package Test;
    import java.io.*;
    public class Dummy1
    public static final int var1= 10;
    public static int varDisp(int var2)
    return(var1+var2);
    This is program is compiling fine.
    I have called the static method varDisp from the class Dummy2 and it is as follows
    package Test;
    import java.io.*;
    public class Dummy2
    public int var3=15;
    public int test=0;
    test+=Dummy1.varDisp(var3);
    and when i compile Dummy2.java, there is a compilation error <identifier > expected.
    Please help me in this program.

    public class Dummy2
    public int var3=15;
    public int test=0;
    test+=Dummy1.varDisp(var3);
    }test+=Dummy1.varDisplay(var3);
    must be in a method, it cannot just be out somewhere in the class!

  • Need help returning an Int!!!

    here is the code for my sport quiz class:
    import javax.swing.*;
    public class Sport
         public static int main (String []args)
    Object[] sportValues = { "Freddie", "jimbo", "the destroyer" };
    Object sportq1;
    Object[] sportValues2 = { "David Beckham", "Alessandro Del Piero",
    "Michael Ballack" };
    Object sportq2;
    Object[] sportValues3 = { "6", "10", "14" };
    Object sportq3;
    int sportScore = 0;
    String message;
    //............QUESTION 1..............
    sportq1 = JOptionPane.showInputDialog(null, "Question 1: What nickname is given to england cricketer andrew flintoff?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
    sportValues, sportValues[0]);
    if (sportq1.equals(sportValues[0]))
    message = "CORRECT!";
    JOptionPane.showMessageDialog(null, message);
    sportScore = (sportScore+1);
         else
         message = "WRONG!";
         JOptionPane.showMessageDialog(null, message);
         //............QUESTION 2.............
    sportq2 = JOptionPane.showInputDialog(null, "Question 2: Who scored italy's second goal in the world cup final?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
    sportValues2, sportValues2[0]);
    if (sportq2.equals(sportValues2[1]))
    message = "CORRECT!";
    JOptionPane.showMessageDialog(null, message);
    sportScore = (sportScore+1);
         else
         message = "WRONG!";
         JOptionPane.showMessageDialog(null, message);
         //............QUESTION 3.............
    sportq3 = JOptionPane.showInputDialog(null, "Question 3: how many players are there in an ice hockey team?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
    sportValues3, sportValues3[0]);
    if (sportq3.equals(sportValues3[0]))
    message = "CORRECT!";
    JOptionPane.showMessageDialog(null, message);
    sportScore = (sportScore+1);
         else
         message = "WRONG!";
         JOptionPane.showMessageDialog(null, message);
         return sportScore;
    i am trying to return the 'sportScore' int to a main quiz class but for some reason it hasnt worked...
    can anyone tell me what i have done wrong?
    thanks alot!

    this is my main quiz class:
    import javax.swing.*;
    public class Quiz
         public static void main (String []args)
             Object[] possibleValues = { "Sport", "Music", "General Knowledge", "TV and Film", "Display Score Board" };
             Object choice;
             do
          choice = JOptionPane.showInputDialog(null,"Welcome to my quiz\nPlease select you category:", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
          possibleValues, possibleValues[0]);
          if  (choice.equals(JOptionPane.CANCEL_OPTION))
        System.exit(0);
        if (choice.equals(possibleValues[0]))
            Sport.doQuiz();
         if (choice.equals(possibleValues[1]))
            Music.doQuiz();
         if (choice.equals(possibleValues[2]))
            General.doQuiz();
        if (choice.equals(possibleValues[3]))
            TV.doQuiz();
        if (choice.equals(possibleValues[4]))
            int sportScore = Sport.doQuiz();
            int tvScore = TV.doQuiz();
            int musicScore = Music.doQuiz();
            int generalScore = General.doQuiz();
            int totalScore = (sportScore+tvScore+musicScore+generalScore);
            JOptionPane.showMessageDialog(null,"Thankyou for taking my quiz!\nhere are your results:\nSport: "
            + sportScore + "/3\nMusic: " + musicScore + "/3\nGeneral Knowledge: "
            + generalScore + "/3\nTV and Film: " + tvScore +"/3\n\nTOTAL: "
            + totalScore + "/12!");
        while(!(choice.equals(possibleValues[4])));
        }as you can see i have more than just the sport category but once i know how to do that one i will be able to do the rest...
    now here is my sport class:
    import javax.swing.*;
    public class Sport
           public static int doQuiz()
              Object[] sportValues = { "Freddie", "jimbo", "the destroyer" };
                Object sportq1;
              Object[] sportValues2 = { "David Beckham", "Alessandro Del Piero",
    "Michael Ballack" };
                Object sportq2;
              Object[] sportValues3 = { "6", "10", "14" };
                Object sportq3;
                int sportScore = 0;
                String message;
         //............QUESTION 1..............
                sportq1 = JOptionPane.showInputDialog(null, "Question 1: What nickname is given to england cricketer andrew flintoff?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
                sportValues, sportValues[0]);
                if (sportq1.equals(sportValues[0]))
                  message = "CORRECT!";
            JOptionPane.showMessageDialog(null, message);
            sportScore = (sportScore+1);
             else
                 message = "WRONG!";
              JOptionPane.showMessageDialog(null, message);
             //............QUESTION 2.............
                sportq2 = JOptionPane.showInputDialog(null, "Question 2: Who scored italy's second goal in the world cup final?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
                sportValues2, sportValues2[0]);
                if (sportq2.equals(sportValues2[1]))
                  message = "CORRECT!";
            JOptionPane.showMessageDialog(null, message);
              sportScore = (sportScore+1);
             else
             message = "WRONG!";
             JOptionPane.showMessageDialog(null, message);
             //............QUESTION 3.............
                sportq3 = JOptionPane.showInputDialog(null, "Question 3: how many players are there in an ice hockey team?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
                sportValues3, sportValues3[0]);
                if (sportq3.equals(sportValues3[0]))
                  message = "CORRECT!";
            JOptionPane.showMessageDialog(null, message);
              sportScore = (sportScore+1);
             else
                 message = "WRONG!";
              JOptionPane.showMessageDialog(null, message);
             return sportScore;
    }i am tring to return sportScore from the sport class to the main quiz class, at the moment instead of getting the sportScore at the end of the quiz class it is now running the whole sport class again!
    what have i done wrong?
    ta

  • How can I make a BufferedImage out of packed and non-packed int pixels?

    Hi all,
    I'm trying to turn a byte array of pixels into an int array, then into a buffered Image. In addition to the pixels, I've also got the color (and alpha) masks, width, height, and bit depth of the image. My problem is that the bits per pixel can change, the individual bytes cannot contain the pixels, and many times an int is not fully utilized to store an entire pixel (16bit pixels, for example). When I attempt to create a WritableRaster with a DataBufferInt, I get errors that I don't get if I re-package the 16bit pixels in a short[], (using DataBufferUShort). I don't want to have to do this, since it means reprocessing the entire array yet another time. One last thing. I've already got a working method for "up-converting" the int[] to 32bit pixels, though I'd love to see somebody else's attempt at this if they'd like to share. Mostly, I'm just looking for a way to use the data I have to create a BufferedImage that preserves the data type of the data. Here's some of the code I'm using now. (The byte array may contain MIPmaps, so that's the reason for the imgIndex...)
    <edit> Sorry, I also don't want to have to use the switch (or if...else) statements. I'm looking for a way to use the info I have to write one piece of code that will work for all the data types...</edit>
    private static int[] get8888(byte[] pixels, int format, int width, int height, int imgIndex) {
       int[] pixels8888 = new int[width * height / (int)Math.pow(4, imgIndex)];
       int offset = 0;
       for(int i = 0; i < imgIndex; i++) {
          offset += (width * height) / (int)Math.pow(4, i);
       switch(format) {
          case TYPE_A8R8G8B8:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = (pixels[(i + offset) * 4] & 0xff) | (pixels[(i + offset) * 4 + 1] & 0xff) << 8 | (pixels[(i + offset) * 4 + 2] & 0xff) << 16 | (pixels[(i + offset) * 4 + 3] & 0xff) << 24;
             break;
          case TYPE_A1R5G5B5:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = pixels[(i + offset) * 2] & 0xff | (pixels[(i + offset) * 2 + 1] & 0xff) << 8;
                int a = ( ( (pixels8888[i] & 0x8000) >>> 15 ) == 1 ) ? 0xFF : 0;
                int r = (pixels8888[i] & 0x7c00) >>> 7;
                int g = (pixels8888[i] & 0x3e0) >>> 2;
                int b = (pixels8888[i] & 0x1f) << 3;
                pixels8888[i] = a << 24 | r << 16 | g << 8 | b;  
             break;
          case TYPE_A4R4G4B4:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = pixels[(i + offset) * 2] | (pixels[(i + offset) * 2 + 1] << 8);
                int a = (pixels8888[i] & 0xf000) >>> 12;
                int r = (pixels8888[i] & 0xf00) >>> 8;
                int g = (pixels8888[i] & 0xf0) >>> 4;
                int b = (pixels8888[i] & 0xf);
                a = a | (a << 4);
                r = r | (r << 4);
                g = g | (g << 4);
                b = b | (b << 4);
                pixels8888[i] = a << 24 | r << 16 | g << 8 | b;  
             break;
          case TYPE_A8R3G3B2:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = pixels[(i + offset) * 2] | (pixels[(i + offset) * 2 + 1] << 8);
                int a = (pixels8888[i] & 0xff00) >>> 8;
                int r = (pixels8888[i] & 0xe0);
                int g = (pixels8888[i] & 0x1c) << 3;
                int b = (pixels8888[i] & 0x3) << 6;
                pixels8888[i] = a << 24 | r << 16 | g << 8 | b;  
             break;
          case TYPE_R8G8B8:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = (pixels[(i + offset) * 3] & 0xff) | (pixels[(i + offset) * 3 + 1] & 0xff) << 8 | (pixels[(i + offset) * 3 + 2] & 0xff) << 16 | 0xff000000;
             break;
          case TYPE_R5G6B5:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = (pixels[(i + offset) * 2] & 0xff) | (pixels[(i + offset) * 2 + 1] & 0xff) << 8;
                int a = 0xFF;
                int r = (pixels8888[i] & 0xf800) >>> 8;
                int g = (pixels8888[i] & 0x7e0) >>> 3;
                int b = (pixels8888[i] & 0x1f) << 3;
                pixels8888[i] = a << 24 | r << 16 | g << 8 | b;  
             break;
          case TYPE_R3G3B2:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = pixels[(i + offset)];
                int a = 0xFF;
                int r = (pixels8888[i] & 0xe0);
                int g = (pixels8888[i] & 0x1c) << 3;
                int b = (pixels8888[i] & 0x3) << 6;
                pixels8888[i] = a << 24 | r << 16 | g << 8 | b;  
             break;
          case TYPE_X8R8G8B8:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = (pixels[(i + offset) * 4]) & 0xff | (pixels[(i + offset) * 4 + 1] & 0xff) << 8 | (pixels[(i + offset) * 4 + 2] & 0xff) << 16 | 0xff000000;
             break;
          case TYPE_X1R5G5B5:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = (pixels[(i + offset) * 2] & 0xff) | (pixels[(i + offset) * 2 + 1] & 0xff) << 8;
                int a = 0xff;
                int r = (pixels8888[i] & 0x7c00) >>> 7;
                int g = (pixels8888[i] & 0x3e0) >>> 2;
                int b = (pixels8888[i] & 0x1f) << 3;
                pixels8888[i] = a << 24 | r << 16 | g << 8 | b;  
             break;
          case TYPE_X4R4G4B4:
             for(int i = 0; i < pixels8888.length; i++) {
                pixels8888[i] = pixels[(i + offset) * 2] | (pixels[(i + offset) * 2 + 1] << 8);
                int r = (pixels8888[i] & 0xf00) >>> 8;
                int g = (pixels8888[i] & 0xf0) >>> 4;
                int b = (pixels8888[i] & 0xf);
                r = r | (r << 4);
                g = g | (g << 4);
                b = b | (b << 4);
                pixels8888[i] = 0xff << 24 | r << 16 | g << 8 | b;  
             break;
          default:
             System.out.println("File type not recognized");
       return pixels8888;
    }After I've done this, I can just create a DataBufferInt with the returned pixel array and generate the bufferedImage. I'm doing this currently, but I'd like to be able to write code that would take the image type and return a matching BufferedImage, (of type TYPE_USHORT_565 for example). Any hints?
    Edited by: Quasi_Stomach on Jul 31, 2009 12:33 PM

    i figured it out myself !!!

  • Loading the final static variables at run time.. Please help

    Hello, fellow developers & Gurus,
    Please help me figure out the best way to do this:
    I need to load all my constants at run time. These are the public static final instance variables. The variables values are in the DataBase. How do I go about loading them.

    Your original question was diffeent, but your further posts show what you really want to do:
    1) all constants in 1 class
    2) available readonly for other classes
    3) updatable during runtime by changing in the database
    Did I understand you right?
    Then smiths' approach solves point 2):
    Instead, make the variables available through a method
    call - that way you avoid the whole final variable
    versus read-only attributes problem.
    //GLOBAL VARIABLES EXPOSED AS PUBLIC PROPERTIES
    public final class GlobalProperties
    public static int getTableSize();
    public static int getRowSize();
    Each "constant" should be a private static variable, and these methods simply return their values.
    The variables are initialized in a static initializer by accessing the db. Ok.
    You habe a table with one row containing as columns all the constants.
    A method readConstants() does a "select constant1, constant2, ... from const_table" and sets all the variables.
    The static initializer calls this method.
    Right?
    Ok, then you simply call readConstants() everytime you want to synchronize with the actual content of const_table.
    Was it this?

  • Pb to get a static variable value from an main program...

    Hi my lifegards !
    I am not a king of java and I thing I need explication about the way to get static values from an other class throw a method...
    here is my objects :
    CapturesBuffer(class extends canvas)
    static int nbCapts...
    public getNbCapts() return nbCaptsSendCapture (servlet)
    "captures = new CapturesBuffer();" in init()
    captures.getNbCapts(); return the good number of capturesSendToPD (program with static void main())
    "captures = new CapturesBuffer();" in constructor
    new SendToPD() in main(String args[])
    captures.getNbCapts(); return a bad value (the initial value)I hope it's anderstandable..:-)
    I have try to instance SendToPD object in the servlet (not to use the main method) and it is working !
    For me it's coming from main method. Am I wrong ?
    And more useful, what is the solution (I hope and I am sure there is one...)
    Thanx a lot and I wish u and happy year with all forms of java
    Guillaume.

    I didn�t understand very weel your aims neither why it is Thread extended .. but, anyway, here comes my guess:
    //package cicv.hatefulworld.server;
    public class DataPict implements Runnable
         private volatile Thread activeInstance = null;
         public void start()
              activeInstance = new Thread(this);
              activeInstance.start();
         public void stop()
              activeInstance = null;
         public void run()
              CapturesBuffer captures = new CapturesBuffer();
              Thread thisInstance = Thread.currentThread();
              try
                   while (activeInstance == thisInstance)
                        int nb = captures.getNbCapt();
                        System.out.println("number of captures: " + nb);
                        thisInstance.sleep(1000); // waiting 1 second
              catch (InterruptedException threadError)
                   System.out.println("Thread error:");
                   threadError.printStackTrace();
              catch(Exception generalError)
                   System.out.println("General error:");
                   generalError.printStackTrace();
              finally
                   captures = null;
                   thisInstance = null;
         public static void main(String[] args)
              (new DataPict()).start();
    class CapturesBuffer
         private int numberOfCaptures = 0;
         public int getNbCapt()
              // I don�t know exactlly what this method is designed for..
              // then I just coded a counter ...
              return numberOfCaptures++;
    }just compile it and run:
    javac *.java
    java DataPict

  • How can i change the class in the Class Library project to be static or public so i can use it from the windows application project ?

    First i know that when i make any changes to the class library project i need to rebuild the project then to remove the Capture.dll from the TestScreenshot project and then to add again the updated Capture.dll
    The problem for example in this case i'm trying to use a public static variable i add in the DXHookD3D9.
    In the DXHookD3D9 i added this public static variable:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    //using SlimDX.Direct3D9;
    using EasyHook;
    using System.Runtime.InteropServices;
    using System.IO;
    using System.Threading;
    using System.Drawing;
    using Capture.Interface;
    using SharpDX.Direct3D9;
    namespace Capture.Hook
    internal class DXHookD3D9: BaseDXHook
    public DXHookD3D9(CaptureInterface ssInterface)
    : base(ssInterface)
    LocalHook Direct3DDevice_EndSceneHook = null;
    LocalHook Direct3DDevice_ResetHook = null;
    LocalHook Direct3DDevice_PresentHook = null;
    LocalHook Direct3DDeviceEx_PresentExHook = null;
    object _lockRenderTarget = new object();
    Surface _renderTarget;
    public static decimal framesperhourtodisplay = 0;
    protected override string HookName
    get
    return "DXHookD3D9";
    List<IntPtr> id3dDeviceFunctionAddresses = new List<IntPtr>(
    framesperhourtodisplay
    The problem is i can't even get to the Capture.Hook namespace and not to the DXHookD3D9 from the TestScreenshot application window project.
    This is a screenshot:
    For example fro the FramesPerSecond class i can use it get to it from the windows forms application.
    namespace Capture.Hook
    /// <summary>
    /// Used to determine the FPS
    /// </summary>
    public class FramesPerSecond
    int _frames = 0;
    int _lastTickCount = 0;
    float _lastFrameRate = 0;
    Since it's public i guess.
    But if i will change the DXHookD3D9 class from internal to public:
    public class DXHookD3D9: BaseDXHook
    I will get error on the DXHookD3D9: 
    Error 1
    Inconsistent accessibility: base class 'Capture.Hook.BaseDXHook' is less accessible than class 'Capture.Hook.DXHookD3D9'
    And the BaseDXHook class:
    namespace Capture.Hook
    internal abstract class BaseDXHook: IDXHook
    protected readonly ClientCaptureInterfaceEventProxy InterfaceEventProxy = new ClientCaptureInterfaceEventProxy();
    public BaseDXHook(CaptureInterface ssInterface)
    this.Interface = ssInterface;
    this.Timer = new Stopwatch();
    this.Timer.Start();
    this.FPS = new FramesPerSecond();
    Interface.ScreenshotRequested += InterfaceEventProxy.ScreenshotRequestedProxyHandler;
    Interface.DisplayText += InterfaceEventProxy.DisplayTextProxyHandler;
    InterfaceEventProxy.ScreenshotRequested += new ScreenshotRequestedEvent(InterfaceEventProxy_ScreenshotRequested);
    InterfaceEventProxy.DisplayText += new DisplayTextEvent(InterfaceEventProxy_DisplayText);
    ~BaseDXHook()
    Dispose(false);
    How can i solve it so i can use the variable framesperhourtodisplay in the DXHookD3D9 class with the TestScreenshot windows forms application ?

    Hi,
    I dont know if it will work here, since I dont know the complete structure, but the base call must be public, if the derived class is public, so the base class is at least as accessible as the derived class.
    Try make the base class public. (And maybe the base-class IDXHook of the base also...)
    Or use a different approach and make only the properties public that are needed to be public by adding an extra class...
    A structure could look like:(you need to create a class thats public in your dll and expose a property, and set this property in the internal class...)
    In the Accessing class (here Form1)
    public partial class Form1 : Form
    public Form1()
    InitializeComponent();
    private void Form1_Load(object sender, EventArgs e)
    C c = new C();
    MessageBox.Show(B.F.ToString());
    and in the class Lib:
    internal class A
    public A()
    B.F = DateTime.Now.Millisecond;
    public class B
    public static int F { get; set; }
    public class C
    public C()
    A a = new A();
    (add a referenc to the class lib from the accessing project)
    Regards,
      Thorsten

  • Using static methods to instantiate an object

    Hi,
    I have a class A which has a static method which instantiates it. If I were to instantiate the class A twice with it's static method within class B then you would think class B would have two instances of class A, right?
    Example:
    class A
       static int i = 0;
       public A(int _i)
           i = _i;
       public static A newA(int _i)
            return new A(_i);
    class B
        public B()
            A.newA(5);
            A.newA(3);
            System.out.println(A.i);
        public static void main(String[] args)
            B b = new B();
    }Is there really two instances of class A or just one? I think it would be the same one because if you check the int i it would be 3 and not 5. Maybe static instantiated objects have the same reference within the JVM as long as you don't reference them yourself?
    -Bruce

    It
    seems like you are the only one having trouble
    understanding the question.Well I was only trying to help. If you don't want any help, its up to you, but if that's the case then I fail to see why you bothered posting in the first place...?
    Allow me to point out the confusing points in your posts:
    you would think class B would have two
    instances of class A, right?The above makes no sense. What do you mean by one class "having" instances of another class? Perhaps you mean that class B holds two static references to instances of Class A, but in your code that is not the case. Can you explain what you mean by this?
    Is there really two instances of class
    A or just one?You have created two instances.
    >I think it would be the same one because if you
    check the int i it would be 3 and not 5.
    I fail to see what that has to do with the number of instances that have been created...?
    Maybe static instantiated objects have the
    same reference within the JVM as long as you
    don't reference them yourself????? What is a "static instantiated object"? If you mean that it was created via some call to a static method, then how is it different to creating an object inside the main method, or any other method that was called by main? (i.e. any method)
    What do you mean by "the same reference within the JVM"? The same as what?
    What happened to the first call "A.newA(5)"?
    I think it was overidden by the second call
    "A.newA(3)".As i already asked, what do you mean by this?
    If you change the line for the constructor
    in A to i = i * i you will get "9" as the
    output, if you delete the call "A.newA(3)"
    you will get "25" as the output. Yes. What part of this is cauing a problem?

Maybe you are looking for

  • Installation and run

    I downloaded camera raw 6.2. Please tell me how to install and run?

  • How do i import music from windows media player to I-tunes?

    can someone please let me know if there is a way to move all of the music i have in Media Player to itunes. Thank you

  • Default app?

    OK, I have 2 copies of an app of different versions. In the "get-info" window I can set which version I want to open an associated document with for that application. The problem is that even when I indicate that I want to use the version that is NOT

  • How to identify TOP 5 SQL consuming more CPU time without using statspack

    How to identify the TOP 5 SQL queries which are consuming more CPU time during the timespan of 24 hours for entire database. There are N number of users who have issued sql queries, out of which few users have disconnected and few user are still conn

  • VD02 Additional Data not editable

    Hi Experts, I am wondering if it is possible to make any of the additional data fields(kna1-katr1 - 5 and knvv-kvgr1 - 5) in the customer master non editable? I see in configuration where we can choose to suppress, make optional, etc some of the cust