Image problem in java

I am experiancing a problem in reading an Image datatype from SQLServer7.0 using java. The Image is created using MSAccess application and I am trying to read the same Image using Java. I am using InputStream to read Image and writing bytes to another file(a.gif). When I opened the image it says invalid format. Below is my code. Help me....
          String s = "select * from Image where IMSCANUSERID='A'";
          java.sql.ResultSet rs = conn.createStatement().executeQuery(s);
          rs.next();
          java.io.InputStream is = rs.getBinaryStream("IMIMAGE");
          java.io.FileOutputStream out = new java.io.FileOutputStream("c:/test1.tif");
          int i;
          while((i=is.read()) != -1)
               out.write((byte)i);     

I am experiancing a problem in reading an Image
datatype from SQLServer7.0 using java. The Image is
created using MSAccess application and I am trying to
read the same Image using Java. I am using InputStream
to read Image and writing bytes to another
file(a.gif). When I opened the image it says invalid
format. Below is my code. Help me....
what format image is it exactly. you say you are saving it as a gif but you seems to be saving at as a tif. these are not the same.
String s = "select * from Image where
e IMSCANUSERID='A'";
java.sql.ResultSet rs =
= conn.createStatement().executeQuery(s);
          rs.next();
java.io.InputStream is =
= rs.getBinaryStream("IMIMAGE");
java.io.FileOutputStream out = new
w java.io.FileOutputStream("c:/test1.tif");
          int i;
          while((i=is.read()) != -1)
               out.write((byte)i);     
          }first find out what format the image is exactly.
then save it as that type.

Similar Messages

  • Problems with image field and java

    Hi, i´m a beginner user of Adobe LiveCycle Designer, i create a form and i fill the text fields with a Java code, but when i try to dinamically assign a image on the image field of my form it doesn´t work, someone have any idea of whats happening or how can i manipulate the image field from Java code? thanks

    Session data will only last as long as the servlet container allows. In most cases (eg Tomcat) this defaults to about 30 minutes, but can be changed. Check that the session timeout configuration in your servlet container hasn't been set to "never timeout".
    Even if it had, I would have expected OutOfMemory errors rather than degrading performance. Although if the max heap size of the JVM has been set to a level higher than the RAM on the machine you could be getting excess page file usage.
    This probably wouldn't put CPU utilization at 99% though.. I suspect this is a code related problem.
    My best guess is one of two reasons:
    1. Somewhere in your code, or someone elses, there is a loop that never ends.
    2. There is a bug in the servlet container.
    I don't know which servlet container you are using, but I have used Tomcat extensively and never seen this behaviour.
    In terms of solving this problem, that's a tough one. I would try running the entire application within a profiling tool to see which threads are clogging up the processor. The Eclipse java IDE has a plugin called Eclipse Profiler which will allow you to track the utilization of code right down to the method level.
    If it were me, I'd be running the entire web application with a profiler like Eclipse Profiler and waiting for it to start clogging, then see who the guilty code is.

  • How to add an image to an IMAGE control in Java WebDynpro

    hi
    How to add an image to an IMAGE control in Java WebDynpro.
    Please give me the steps to assign an image to an IMAGE control.
    Advanced Thanks
    brahma

    Thank You Mathan MP,
    i tried these steps, but whenever i selected the source property of image UI control, it opens a context window, but this context window does't contain any thing for selection.
    so how to solve this problem ?
    the link whatever u provided is not opened, please send the correct link.
    http://127.0.0.1:1284/help/index.jsp?topic=/com.sap.devmanual.doc.user/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm
    Thanks in Advance
    brahma

  • How to embed the Images in the java sourse

    How to embed the Images in the java sourse
    The size of the file will be too large while I put the binary code of the image into the java sourse!
    thanks

    You could encrypt them with a private key and then
    decrypt them with a public key.
    Almost had it... public key encryption works the other
    way around... otherwise what's the point of
    encrypting... if the decryption key is public?Spinoza's right. Public key encryption works both ways, but it would be useless in this case to encrypt with the private key. The problem is, how do you package your private key with the application in a way that doesn't allow the user to get it? Encrypt it? :-) I agree that there's no point to this exercize. If users want to screw up the application by editing its image files, let 'em.

  • BIG Problem with java 1.4 headless mode!!!!

    Hello,
    I try to build in a get method of a servlet an image to send to the client http.
    On my server obviously I havent a display thus I looked for some packages that cuold solve the problem of "CANT COONECT TO X11 ecc.".
    I found three solution:
    1 A virtual frame buffer but It isnt a good solution for me because if 500 users try to connect to my servlet at the same time only one frame buffer could be a problem and It isn't an elegant solution.
    2 A Use pja on my server it dont work I dont know why.
    I have set the System.setProperty("awt.toolkit","com.eteks...PjaToolkit) but it dont work when I try to instaziate a Panel (of Pja types) It give me an exception.
    3 The choose I prefer but It still dont work. Use Java 1.4 beta 3. I try to use this version because it has headles support but it dont work and I see in the bugs database that I'm not the only one that keep this problem in Servlet environment. In the doGet method of my Servlet I use the System.SetProperty("java.awt.headless","true") command to turn on headless support but when I try to instanziate a Panel or a Frame I get the exception HeadlessException.
    Have someone use this property of the jdk 1.4 and could give me some hints.
    I try to change my Xbootclasspath in the zone.properties of my Apache Server through wrapper.bi9n.parameter but I didnt have better result.
    Cuold someone help or I'll cry for all the xmas holiday :-)
    Thank you very much Ponzetti76

    what a pity! I still haven't found a solution for the problem rajsaini mentioned one year ago! I also wrote a class for resizing an image after uploading a file. When I call the mehtod the first time from a jsp a get the error "can't connect to X server .." and when a try it second time I receive NoClassDefFoundError.
    Here is the code of the class I try to call from a jsp
    import java.io.*;
    import java.awt.image.*;
    import java.awt.*;
    import javax.imageio.ImageIO;
    public class imgUp {
    public imgUp() {
    public void generateThumbnail(String fileName, int maxSize) {
    System.setProperty ("java.awt.headless", "true");
    System.out.println("Headless is " +
    System.getProperty"java.awt.headless"));
    try {
    String orgFileName = fileName;
    File orgImgFile = new File(orgFileName);
    String newFileName = orgImgFile.getParent() + "/th_" +
    orgImgFile.getName();
    // read image
    BufferedImage orgImage = ImageIO.read(orgImgFile);
    BufferedImage resizedImage = null;
    // resizing ;))
    int orgImageWidth = orgImage.getWidth(null);
    int orgImageHeight = orgImage.getHeight(null);
    int resizeImageWidth = 0;
    int resizeImageHeight = 0;
    if (orgImageWidth > orgImageHeight) {
    resizeImageWidth = maxSize;
    resizeImageHeight = (maxSize * orgImageHeight) / orgImageWidth;
    } else {
    resizeImageWidth = (maxSize * orgImageWidth) / orgImageHeight;
    resizeImageHeight = maxSize;
    resizedImage = new BufferedImage(resizeImageWidth,resizeImageHeight, Image.SCALE_SMOOTH);
    // Copy image to buffered image.
    Graphics g = resizedImage.createGraphics();
    g.drawImage(orgImage, 0, 0,resizeImageWidth, resizeImageHeight,null);
    /* write the jpeg to a file */
    File file = new File(newFileName);
    ImageIO.write(resizedImage, "jpg", file);
    catch (Exception e){
    System.out.println("exception");
    The strange thing this Exception is never triggerd
    and heres the code of the calling jsp :
    if(request.getParameter("upnow") != null && request.getParameter("upnow").equals("now")){
    imgUp.generateThumbnail("/www/demo/imageupload/i.jpg", 100);
    I set a System.out.println ... after each command of the class and I found out it crashes while this : Graphics g = resizedImage.createGraphics();
    The last thing I want to add is, that the commandline version of class works perfectly.
    Systemenv:tomcat 4.1.18, jdk 1.4
    Thanks for any ideas in advance

  • Help...Image problem

    Hi.
    I have something like this:
    import java.awt.*;
    import java.awt.event.*;
    public class viewerS extends Frame
    Toolbar toolbar;
    Canvas cv = new Canvas();
    BorderLayout layout = new BorderLayout();
    public viewerS ()
    this.setSize(240,320);
    this.setLayout(layout);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image img = toolkit.getImage("documentbar24.jpg");
    Toolbar toolbar = new Toolbar(img);
    this.add(toolbar, BorderLayout.NORTH);
    this.add(cv, BorderLayout.CENTER);
    public static void main(String args[])
    viewerS viewer = new viewerS();
    viewer.show();
    the problem is that the space allocated for the toolbar is short and i only can see half image(documentbar24.jpg).
    What should i do to see the whole image?
    Thanks.

    here it is:
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;
    public class Toolbar extends Panel
         final static int NUM_AREAS = 240/24;
         final static int A = 0;
         final static int B = 1;
         final static int C = 2;
         final static int D = 3;
         final static int E = 4;
         final static int F = 5;
         Rectangle areas[];
         Image imageSource;
    public Toolbar(Image img)
         setSize(new Dimension(240,40));     
         setBounds(new Rectangle(0,0,240,40));
         setBackground(Color.lightGray);
    System.out.println(NUM_AREAS);
    areas = new Rectangle[NUM_AREAS];
    Rectangle r = new Rectangle(0,0,24,18);
    for(int i=0; i < NUM_AREAS; i++)
    areas= new Rectangle(r);
    r.x += 24; // width of the button
    this.imageSource = img;
    validate();
    public void paint(Graphics g)
         //System.out.println(areas[0].toString());
         Color red = Color.red;
         Color green = Color.green;
         Color blue = Color.blue;
         for(int i=0; i < NUM_AREAS; i++)
              Rectangle r = areas[i];
              g.setColor(new Color(25*i,0,0));
              g.fillRect(r.x,r.y,r.width,r.height);
         g.drawImage(imageSource,0,0,240,20,this);
         //g.setColor(new Color(255,0,0));
         //for(int i=0; i < NUM_AREAS; i++)
         //areas[i]= new Rectangle(r);
         //r.x += 40;
              //g.fillRect(0,0,240,10);
              //g.fillRect(
    public boolean mouseUp(Event evt, int x, int y)
         for (int i = 0; i < NUM_AREAS; i++)
    if (areas[i].inside(x, y))
    command(i);
    break;
    return true;
    void command(int code)
    switch(code)
    case A:
         System.out.println("Area" + A);
    //app.link();
    break;
    case B:
         System.out.println("Area" + B);
    //app.move();
    break;
    case C:
         System.out.println("Area" + C);
    //panel.zoomOut();
    break;
    case D:
         System.out.println("Area" + D);
    //panel.zoomIn();
    break;
    case E:
         System.out.println("Area" + E);
    //panel.origView();
    break;

  • Transparent image problem

    Hi all,
    I have two images of the world, both of exactly the same size. The first is a background, and provides texture. The second image goes on top and is supposed to be transparent to let the texture show through. My problem is that when i display the 'transparent' image on top, you cannot see the contours through it, instead the top image just appears a pale colour because of the transparency added to it, as opposed to actually being transparent. Here is my code:
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    public class GamePane extends Canvas {
        /** Creates a new instance of GamePane */
        public GamePane() {
            try {
                buff1 = ImageIO.read(getClass().getResource("images/map_background.gif"));
                buff2 = ImageIO.read(getClass().getResource("images/map.gif"));
            catch (IOException ioe) {
                System.out.println("Problem reading in file: " + ioe);
        public void paint(Graphics g) {
            g.drawImage(buff1, 0, 0, null);
            g.drawImage(buff2, 0, 0, null); //the transparent image
        Image img;
        BufferedImage buff1;
        BufferedImage buff2;
    }Can anyone suggest where i am going wrong?
    Many thanks

    As I understand you right, you want to use a top layered image with transparent parts. If this is the case, you should use the same color for all transparent parts in the picture and use a paint program to change the transparent color to the color mentioned. I use always microsoft paint to do this. (picture-attributes-transparent...)
    the colored parts will automatically appear transparent.

  • Applet - Create image problem

    I have an applet that draws scribble and send to Server. Server save the image drawn in applet.
    Server side I have no problem. How much bytes are available in client side, same as I get in server side. So i have no doubt in server side code.
    When I drawn simple 2 or three lines, then The image is looking ok.
    But when i try to draw scribbling more, then the image is corrupted.
    I dont know where am doing wrong.
    Applet code :
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    public class Scribble_Send extends Applet {
        private int last_x = 0;
        private int last_y = 0;
        private Color current_color = Color.black;
        private Button clear_button;
        BufferedImage bi =new BufferedImage(400,280,BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = (Graphics2D)bi.createGraphics();
        public void init() {
             this.setBackground(Color.lightGray);
             Button b = new Button("save");
             b.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent ae) {
              showStatus("button pressed");
               try {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
              ImageIO.write(bi,"JPEG",baos);
              byte[] buf = baos.toByteArray();
                    showStatus("buf length"+buf.length);
                    URL servletURL = new URL(getCodeBase(),"/servlet/Write_Scribble");
                  URLConnection servletConnection = servletURL.openConnection();
              servletConnection.setDoOutput(true);
              servletConnection.setUseCaches(false);
                    OutputStream os = servletConnection.getOutputStream();
                    os.write(buf);
                 }catch (Exception e) {
                 showStatus(e.toString());
          add(b);
        public boolean mouseDown(Event e, int x, int y)
            last_x = x; last_y = y;
            return true;
        public boolean mouseDrag(Event e, int x, int y)
            Graphics g = this.getGraphics();
            g.setColor(current_color);
            g.drawLine(last_x, last_y, x, y);
            g2.setColor(Color.white);
            g2.drawLine(last_x, last_y, x, y);
            last_x = x;
            last_y = y;
            return true;
    }And Server Side:
    public class Write_Scribble extends HttpServlet {
         public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
           Writer writer = null;
          try{
              InputStream in = req.getInputStream();
                ServletContext servletContext = getServletContext();
                String file = servletContext.getRealPath("/hello.jpg");
                int count, offset = 0;
              byte[] buff = new byte[65536];
                FileOutputStream fis = new FileOutputStream(file);
                while ((count = in.read(buff)) > 0)
                     fis.write(buff,offset,count);
                   offset += count;
              fis.flush();
              fis.close();
          catch (Exception e)
                log("Exception"+e);
              e.printStackTrace();
    }  Help me regarding creating an Image in memory.
    Thanks
    Sharmila A

    thank u it is now working by u r first solution.i hv another
    question if u hv time plz,i m putting this code in form
    form=new form("\u639\u634\u634");
    it is giving me unicode characters but not in concatenated form but
    it is giving me each character separately and so no valid world becomes.
    More over i m doing work on internationalization on mobile plz can u
    give me some help by giving some suggestion.
    thanx again.

  • Blackjack drawing multiple images problem

    Hi. Im making a blackjack game and im having some trouble drawing the images.
    The drawing is fine. But the problem is when to draw new cards. I dont know how to draw a new card without the old one dissapearing. I understand why it dissapears as the code is now, but i dont know how to fix it. Somehow i have to make each card beeing able to paint itself on the board? The filenames of the images to be drawn is fetched by the getCard() in the card class. Since blackjack doesnt use that many cards in play at the same time its possible to simply make more image variables and some if statements deciding which to paint, but that sollution isnt very nice, and i want to make more advanced cardgames after this, so if someone could help me with this it would truly be great.
    Thanks.
    Image displaying board after first new card is dealed, and third one
    http://www.wannerskog.com/newcards.jpg
    Card Class
    public class Card {
         private int value;
         private String color;
         public Card(String incolor,int invalue) {
              value = invalue;
              color = incolor;
         public String getCard() {
              return value+color;
         public int getValue() {
              return value;
    Deck
    import java.util.*;
    //Creates a deck of cards
    public class Deck {
         Card card;
         private Set deck = new HashSet();
         List deck2;
         public void createDeck() {
              for(int i=2; i<=14; i++) {
                   card = new Card("s",i);
                   deck.add(card);
              for(int i=2; i<=14; i++) {
                   card = new Card("h",i);
                   deck.add(card);
              for(int i=2; i<=14; i++) {
                   card = new Card("c",i);
                   deck.add(card);
              for(int i=2; i<=14; i++) {
                   card = new Card("d",i);
                   deck.add(card);
              deck2 = new Vector(deck);
         public void shuffleDeck() {
              Collections.shuffle(deck2);
         public List getDeck() {
              return deck2;
    Dealer Class
    import java.util.*;
    public class Deal {
         Deck deck = new Deck();
         private String card1;
         private String card2;
         public Deal() {
              deck.createDeck();
              deck.shuffleDeck();
         public void dealCards(int j) {
              deck.shuffleDeck();
              List d = (List)deck.getDeck();
              Card card;
              Iterator it = d.iterator();
              String card1 = "";
              String card2 = "";
              for(int i=1; i<=j; i++) {
                   card = (Card)it.next();
                   if(i==1) card1 = card.getCard();
                   if(i==2) card2 = card.getCard();
              this.card1 = card1;
              this.card2 = card2;
         public String getCard1() {
              return card1;
         public String getCard2() {
              return card2;
    Jpanel displaying the buttons
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Controll extends JPanel {
         JButton deal = new JButton("Deal");
         JButton newcard = new JButton("New card");
         JButton stay = new JButton("Stay");
         JButton exit = new JButton("Exit");
         public Controll(View view) {
         final Deal d = new Deal();
         final View v = view;
              class ChoiceListener implements ActionListener
                   int i=0;
                   public void actionPerformed(ActionEvent event) {
                        if("deal".equals(event.getActionCommand()))
                             d.dealCards(2);
                             stay.setEnabled(true);
                             newcard.setEnabled(true);
                             deal.setEnabled(false);
                             v.dealCards(d.getCard1(),d.getCard2());
                             v.resetNew();
                             v.repaint();
                             i=0;
                        if("exit".equals(event.getActionCommand()))
                             System.exit(0);
                        if("newcard".equals(event.getActionCommand()))
                             if(i != 3) {
                                  d.dealCards(1);
                                  v.newCard(d.getCard1(),20);
                                  v.repaint();
                                  i++;
                             if(i == 3) {
                                  newcard.setEnabled(false);
                                  stay.setEnabled(false);
                                  deal.setEnabled(true);
                        if("stay".equals(event.getActionCommand()))
                             deal.setEnabled(true);
                             stay.setEnabled(false);
                             newcard.setEnabled(false);
              Color c = new Color(0, 0, 100);
              setPreferredSize(new Dimension(400, 40));
              setBackground(c);
              ActionListener listener = new ChoiceListener();
              deal.setActionCommand("deal");
              exit.setActionCommand("exit");
              newcard.setActionCommand("newcard");
              stay.setActionCommand("stay");
              exit.addActionListener(listener);
              deal.addActionListener(listener);
              newcard.addActionListener(listener);
              stay.addActionListener(listener);
              add(deal);
              add(newcard);
              add(stay);
              add(exit);
              stay.setEnabled(false);
              newcard.setEnabled(false);
    JPanel displaying the board with cards
    import java.awt.*;
    import javax.swing.*;
    import java.awt.image.*;
    import java.awt.event.*;
    public class View extends JPanel {
         String dealcard1;
         String dealcard2;
         String newcard;
         int i;
         private Image cardimage1 = null;
         private Image cardimage2 = null;
         private Image cardimage3 = null;
         public View() {
              Color c = new Color(0, 100, 0);
              setPreferredSize(new Dimension(400, 300));
              setBackground(c);
         public void dealCards(String incard1, String incard2) {
              dealcard1 = incard1;
              dealcard2 = incard2;
         public void newCard(String incard3,int j){
              newcard = incard3;
              i = i+j;
         public void resetNew() {
              i=0;
              newcard = "";
         public void paint(Graphics g) {
              super.paint(g);
              Toolkit kit = Toolkit.getDefaultToolkit();
              cardimage1 = kit.getImage("CardImages/"+dealcard1+".gif");
              cardimage2 = kit.getImage("CardImages/"+dealcard2+".gif");
              cardimage3 = kit.getImage("CardImages/"+newcard+".gif");
              g.drawImage(cardimage1,80,200,this);
              g.drawImage(cardimage2,100,200,this);
              g.drawImage(cardimage3,180+i,200,this);
    Main
    import javax.swing.*;
    import java.awt.*;
    public class Main
         public static void main(String[] args)
                   JFrame frame = new JFrame("card");
                   View v = new View();
                   Controll c = new Controll(v);
                   frame.getContentPane().add(v, BorderLayout.NORTH);
                   frame.getContentPane().add(c, BorderLayout.SOUTH);
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   frame.pack();
                   frame.show();
    }

    Actually, your app looks okay. Since you asked for some ideas I made some changes, including changing the name of some classes, variables and the image folder. I put all the files in one because I'm lazy. Score is the only class without changes. And nice images.
    Some suggestions:
    1 � try to keep the responsibilities of the View/CardTable class limited to rendering images. You only need to load an image once; continual loading makes for slow performance. If you are using j2se 1.4+ you can use the ImageIo read methods and could then load the images in the Deck class, eliminating the need to pass the images to Deck from View/CardTable (which is an ImageObserver needed for the MediaTracker).
    2 � let the classes do more of the work, eg, Deal/Dealer can add the new cards to the View/CardTable. This will simplify the event code. The ChoiceListener class could be an inner named/nested class and will be easier to follow/maintain if removed from the class constructor.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    public class CardGame
        public static void main(String[] args)
            JFrame frame = new JFrame("card");
            CardTable table = new CardTable();
            Controller control = new Controller(table);
            frame.getContentPane().add(table, BorderLayout.NORTH);
            frame.getContentPane().add(control, BorderLayout.SOUTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
    class CardTable extends JPanel {
        Image[] images;
        Image cardBack;
        private String score;
        List player, house;
        public CardTable() {
            loadImages();
            score = "0";
            player = new ArrayList();
            house = new ArrayList();
            Color c = new Color(0, 100, 0);
            setPreferredSize(new Dimension(400, 300));
            setBackground(c);
        public void setScore(int score) {
            this.score = String.valueOf(score);
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            int x = 80, y = 50;
            Card card;
            for(int j = 0; j < house.size(); j++) {
                card = (Card)house.get(j);
                if(j == 0)
                    g.drawImage(cardBack, x, y, this);
                else
                    g.drawImage(card.getImage(), x, y, this);
                x += 20;
            x = 80; y = 200;
            for(int j = 0; j < player.size(); j++)
                card = (Card)player.get(j);
                g.drawImage(card.getImage(), x, y, this);
                x += 20;
            g.setColor(Color.white);
            g.drawString("Score: " + score, 345, 15);
        public void reset() {
            player.clear();
            house.clear();
            repaint();
        public void addCard(Card card)
            player.add(card);
            repaint();
        public void addDealerCard(Card card)
            house.add(card);
            repaint();
        private void loadImages() {
            String[] suits = { "c", "h", "s", "d" };
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            MediaTracker tracker = new MediaTracker(this);
            cardBack = toolkit.getImage("cards/00w.gif");
            tracker.addImage(cardBack, 0);
            images = new Image[suits.length * 13];
            int index = 0;
            for(int j = 0; j < suits.length; j++)
                for(int k = 2; k < 15; k++)
                    String fileName = "cards/" + k + suits[j] + ".gif";
                    images[index] = toolkit.getImage(fileName);
                    tracker.addImage(images[index], 0);
                    index++;
            try
                tracker.waitForAll();
            catch(InterruptedException ie)
                System.out.println("Image loading in CardTable interrupted: " +
                                    ie.getMessage());
    class Controller extends JPanel {
        CardTable table;
        Dealer d;
        JButton deal, newcard, stay, exit;
        public Controller(CardTable ct) {
            table = ct;
            d = new Dealer(table, table.images);
            Color c = new Color(0, 0, 100);
            setPreferredSize(new Dimension(400, 40));
            setBackground(c);
            deal = new JButton("Deal");
            newcard = new JButton("New card");
            stay = new JButton("Stay");
            exit = new JButton("Exit");
            deal.setActionCommand("deal");
            exit.setActionCommand("exit");
            newcard.setActionCommand("newcard");
            stay.setActionCommand("stay");
            ActionListener listener = new ChoiceListener();
            exit.addActionListener(listener);
            deal.addActionListener(listener);
            newcard.addActionListener(listener);
            stay.addActionListener(listener);
            add(deal);
            add(newcard);
            add(stay);
            add(exit);
            stay.setEnabled(false);
            newcard.setEnabled(false);
        private class ChoiceListener implements ActionListener {
            public void actionPerformed(ActionEvent event) {
                String ac = event.getActionCommand();
                if(ac.equals("deal")) {
                    d.prepareDeck();
                    table.reset();
                    d.dealCards(2);
                    d.dealDealerCards(2);
                    stay.setEnabled(true);
                    newcard.setEnabled(true);
                    deal.setEnabled(false);
                    Score s = d.getScore();
                    table.setScore(s.getScore());
                if(ac.equals("exit"))
                    System.exit(0);
                if(ac.equals("newcard"))
                    d.dealCards(1);
                    Score s = d.getScore();
                    table.setScore(s.getScore());
                    if(s.getScore() > 21) {
                        stay.setEnabled(false);
                        newcard.setEnabled(false);
                        deal.setEnabled(true);
                        s.resetScore();
                if(ac.equals("stay"))
                    deal.setEnabled(true);
                    stay.setEnabled(false);
                    newcard.setEnabled(false);
                    Score s = d.getScore();
                    table.setScore(s.getScore());
    class Dealer {
        CardTable table;
        Deck deck;
        Iterator it;
        private int score;
        private int dealerScore;
        Score s;
        public Dealer(CardTable ct, Image[] images) {
            table = ct;
            deck = new Deck(images);
            score = 0;
            dealerScore = 0;
            s = new Score();
        public void dealCards(int j) {
            Card card;
            for(int i = 0; i < j; i++) {
                card = (Card)it.next();
                table.addCard(card);
                if(card.getValue() > 10)
                    score += 10;
                else
                    score += card.getValue();
            s.setScore(score);
            score = 0;
        public void dealDealerCards(int j) {
            Card card;
            for(int i = 0; i < j; i++) {
                card = (Card)it.next();
                table.addDealerCard(card);
                if(card.getValue() > 10)
                    dealerScore += 10;
                else
                    dealerScore += card.getValue();
            s.setDealerScore(dealerScore);
            dealerScore = 0;
        public void prepareDeck() {
            deck.shuffle();
            it = deck.getCards().iterator();
        public Score getScore() {
            return s;
    class Score {
        private int score;
        public void setScore(int s) {
            score = score + s;
        public void resetScore() {
            score = 0;
        public int getScore() {
            return score;
        private int dealerScore;
        public void setDealerScore(int s) {
            dealerScore = dealerScore + s;
            System.out.println("DEALER: " + dealerScore);
        public void resetDealerScore() {
            dealerScore = 0;
        public int getDealerScore() {
            return dealerScore;
    class Deck {
        List cards;
        public Deck(Image[] images) {
            cards = new ArrayList();
            createDeck(images);
        private void createDeck(Image[] images) {
            for(int j = 0; j < images.length; j++)
                int value = j % 13 + 2;
                cards.add(new Card(images[j], value));
        public void shuffle() {
            for(int j = 0; j < 4; j++)
                Collections.shuffle(cards);
        public List getCards() {
            return cards;
    class Card {
        private Image image;
        private int value;
        public Card(Image image, int value) {
            this.image = image;
            this.value = value;
        public Image getImage() {
            return image;
        public int getValue() {
            return value;
    }

  • Image Processing in Java (E-Book) Request

    Can anyone post the links for this e-book
    i think this e-book is helpful.so,iam requesting all of you.
    Image Processing in Java
    by Douglas A. Lyon
    Publisher: Prentice Hall PTR; Bk&CD-Rom edition (March 1, 1999)
    Language: English
    ISBN: 0139745777

    Check ebay, amazon or your local seller for a copy. Or if you want a free copy, write the author (maybe he's a generous fellow), but don't bother people on this forum with posts like this.
    - Travis

  • Image processing in JAVA

    I m working on an image processing project and I want to know how JAVA supports image processing. Does it have proper API's for image handling and etc... And also about the performance, as JAVA would be slow for high processing jobs.
    Any suggestions as to wat should be the best platform for working on it.

    Some good books on this topic:
    Digital Image Processing: a practical introduction using Java.
    by Efford
    Building Imaging Applications with Java Technology.
    by Rodrigues
    Image Processing in Java.
    by Lyon

  • Problem with Java and Windows (Mainly Vista and UAC)

    Hi all,
    I am having a problem with a program that I've devoloped. The program itself is packaged as a jar and I plan to deploy it across multiple platforms eventually however right now i am only concerned about windows based systems. I have made an installer for a windows baised systems using NSIS to install the software files. I made the installer as I need several java packages to be installed so the program would work (JAI, J3D, JAI ImageIO) and I also require the program to have fileassociations on windows.
    I know that this is not what java is about, however the majority of the users will be on windows baised systems so I've decided that OS specific installers is the best option.
    During the process I have noticed that there are several key problem with java for this type of application!
    The first issue that I have come across is getting file associations to work on java. As a .jar is not an excutable it is not possible to directly associate a filetype with it in java so to overcome this I currently run the program from a .bat files and also the program requires large memory so this also allows me to run the program with -xmx. The batch file that I use is :
    <code>
    cd PATH TO PROGRAM
    start javaw -Dsun.java2d.noddraw=true -Xmn100M -Xms500M -Xmx1000M -jar "PATH TO PROGRAM\program.jar" %1 -vram 134217728
    pause;
    </code>
    Ok so all this appears to work fine and allows windows to have file associations and start the program and thats all works perfectly but this is a non-ideal solution. Has anyone got any advice on improving this?
    The next problem that I have appears to be a problem with Vista and UAC (user access control). When a user installs the program and installs the program into the program files directory I found that the program did not work and kept saying that I did not have access to the files in the current directory. This is a problem as I read and write settings files during program execution.
    On a Vista system UAC prevents file write operations into the Program Files directory unless the program has requested elevated status even if the user is a full administrator. The probem is that there appears to be no real way to achieve this under java that I'm aware of...
    Has anyone else had this probem and has a suitable solution?
    Any advice on these issues would realy be appricated.
    Regards
    Joey

    Ok so i've kinda found a solution, its not ideal but its very good. I found this program called Elevate
    A link to the site I got it was
    http://www.wintellect.com/cs/blogs/jrobbins/archive/2007/03/27/elevate-a-process-at-the-command-line-in-vista.aspx
    This program allows you start java with a UAC dialog for high access using
    Elevate java -jar myjar.jar
    This then allows you to have full access using java... I guess it could be dangerous but it does the job.

  • Problem with java and pogo games

    i use mozilla and now with the problems with java and hackers cannot play my pogo games,what can i do? i disabled my java i tried java 6 doesnt work or is not safe,what is a safe way to play games on pogo that use java?

    Oracle has released a Java 7 Update 11 to address security vulnerabilities and you should update to that version.
    *https://support.mozilla.org/kb/how-to-use-java-if-its-been-blocked
    See also:
    *http://kb.mozillazine.org/Java#Windows_installation_issues
    You can find the latest Java version on the Oracle website.
    See Java Platform > Java SE 7U11 and Java 6U38 (Download JRE)
    *http://www.oracle.com/technetwork/java/javase/downloads/index.html

  • Problem with java swing button and loop

    Problem with java swing button and loop
    I�m using VAJ 4.0. and I�m doing normal GUI application. I have next problem.
    I have in the same class two jswing buttons named start (ivjGStart) and stop (ivjGStop) and private static int field named Status where initial value is 0. This buttons should work something like this:
    When I click on start button it must do next:
    Start button must set disenabled and Stop button must set enabled and selected. Field status is set to 1, because this is a condition in next procedure in some loop. And then procedure named IzvajajNeprekinjeno() is invoked.
    And when I click on stop button it must do next:
    Start button must set enabled and selected and Stop button must set disenabled.
    Field status is set to 0.
    This works everything fine without loop �do .. while� inside the procedure IzvajajNeprekinjeno(). But when used this loop the start button all the time stay (like) pressed. And this means that a can�t stop my loop.
    There is java code, so you can get better picture:
    /** start button */
    public void gStart_ActionEvents() {
    try {
    ivjGStart.setEnabled(false);
    ivjGStop.setEnabled(true);
    ivjGStop.setSelected(true);
    getJTextPane1().setText("Program is running ...");
    Status = 1;
    } catch (Exception e) {}
    /** stop button */
    public void gStop_ActionEvents() {
    try {
    ivjGStart.setEnabled(true);
    ivjGStart.setSelected(true);
    ivjGStop.setEnabled(false);
    getJTextPane1().setText("Program is NOT running ...");
    Status = 0;
    } catch (Exception e) {
    /** procedure IzvajajNeprekinjeno() */
    public void IzvajajNeprekinjeno() {  //RunLoop
    try {
    int zamik = 2000; //delay
    do {
    Thread.sleep(zamik);
    PreberiDat(); //procedure
    } while (Status == 1);
    } catch (Exception e) {
    So, I'm asking what I have to do, that start button will not all the time stay pressed? Or some other aspect of solving this problem.
    Any help will be appreciated.
    Best regards,
    Tomi

    This is a multi thread problem. When you start the gui, it is running in one thread. Lets call that GUI_Thread so we know what we are talking about.
    Since java is task-based this will happen if you do like this:
    1. Button "Start" is pressed. Thread running: GUI_Thread
    2. Event gStart_ActionEvents() called. Thread running: GUI_Thread
    3. Method IzvajajNeprekinjeno() called. Thread running: GUI_Thread
    4. Sleep in method IzvajajNeprekinjeno() on thread GUI_Thread
    5. Call PreberiDat(). Thread running: GUI_Thread
    6. Check status. If == 1, go tho 4. Thread running: GUI_Thread.
    Since the method IzvajajNeprekinjeno() (what does that mean?) and the GUI is running in the same thread and the event that the Start button has thrown isn't done yet, the program will go on in the IzvajajNeprekinjeno() method forever and never let you press the Stop-button.
    What you have to do is do put either the GUI in a thread of its own or start a new thread that will do the task of the IzvajajNeprekinjeno() method.
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    This tutorial explains how to build a multi threaded gui.
    /Lime

  • I have a problem with Java and an e-procurement system integrating

    I use an e-procurement system at work and yesterday I could not get my parts list from the suppliers web site to display in our in-house eprocurment finance package.
    There is not a problem with the finance package. There is not a problem with the suppliers web site. I have verified both of these by other colleagues being able to complete what I am trying to do.
    The difference between my version of Firefox and my colleagues' is that I am on version 6.0.1 and they are on 6.0.
    I have had problems with Java not displaying certain animations on the suppliers web site but, my colleague does not and I am suspicious that this is the problem. Can anyone verify this please and what can I do about it. My Java updates are up-to-date as of yesterday and are automatic.
    Thanks.

    I was quite amazed I never got a reply to this, in the past people here have been helpful. In any case I was finally able to enter this website on the exceptions list in the Java panel, and I believe it is okay  now.

Maybe you are looking for

  • Moving iTunes from PC to Mac OSX possible?

    Hi, My friend has bought a new Mac with OSX 10.5 and wants me to move his iTunes from his PC to Mac, now I can get all the music copied over as I have set the network up and can browse to both computers. iTunes is installed on the Mac but empty, what

  • Basic question about Flash video. Please Help

    Hello, Sorry for the noob question but I'm struggling with the basic understanding about the Flash video. I just need to reduce a large video file to a small size with a nice quality and the Flash Video Encoder does very god job with that. But when I

  • Problems restoring iPhone

    I can't restore my iPhone. I've done the list for restoring my iPhone twice, and "error 21" (or something lke that) appears. I want to restore because i want to "start over". One of my sisters friends jailbroke it and said everything would be much be

  • Broadband router

    Hi, I'm moving to a new property, and have ordered broadband which will be activated in 2 weeks. The router is due to arrive on the same day as the broadband will be activated. If I'm not around on the day to sign for the router, will I be able to us

  • Remove blue line in spectral analysis; paintbrush not selectable

    I'm trying to remove a persons talking from a sound file.  His talking shows up in spectral analysis as the color blue.  Is there some way to select and mute it?  The paintbrush is not selectable, tried to do this manually.  Audition clearly identifi