how to convert byte array to images

hi folks

i want to display some images in the jsp. by taking

the images from DataBase ,i already inserted the image into

the dataBase as a BLOB and i have retrived the image from DataBase

as a byte array

now i dont no how to convert the byte array to image

iam using struts and hibernate

eagerly waiting for your replies

Posted On: Monday 22nd of October 2012 06:23:47 AM Total Views:  274
View Complete with Replies

Related Messages:

how to get colored line to differentiate text field array in swing   (142 Views)
I have developed one frame on which I used GridBagLayout to arrange textfields of 12X12. i.e., total 144 textfields on frame. Now I want to differentiate these text fields with colored line after each 3 columns and three rows as shown in the following diagram. I shouldn't change the names of that text fields, because I interrelated those text fields using their names as jt[0][0], jt[0][1]......jt[6][2]........ and So on.I tried in many ways, but I couldn't find the solution. Please suggest. Below is the some part of my code.
Jcheckbox array with various Listener!   (149 Views)
I get base source code in this. I change it as bellow import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class SelectingCheckBox { static int number = 0; static AbstractButton abstractButton; static int numberCheckboxes = 4; static boolean selected; static ButtonModel buttonModel; static boolean armed; public static void main(String args[]) { JFrame frame = new JFrame("Selecting CheckBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { abstractButton = (AbstractButton) actionEvent.getSource(); selected = abstractButton.getModel().isSelected(); }}; ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { abstractButton = (AbstractButton) changeEvent.getSource(); buttonModel = abstractButton.getModel(); }}; ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { abstractButton = (AbstractButton) itemEvent.getSource(); selected = abstractButton.getModel().isSelected(); int state = itemEvent.getStateChange(); abstractButton.setName(Integer.toString(number)); if (state == ItemEvent.SELECTED) { number = number + 1; abstractButton.setName(Integer.toString(number)); for (int i = 0; i < numberCheckboxes; i++) { if (Integer.parseInt(abstractButton.getName()) != i) { abstractButton.setEnabled(false); } else { abstractButton.setEnabled(true); System.out.println("abstractButton.getName() ="+ abstractButton.getName()); }}} else { number = number - 1; }}}; Container contentPane = frame.getContentPane(); frame.getContentPane().setLayout(null); JCheckBox[] checkBoxes = new JCheckBox[numberCheckboxes]; for (int i = 0; i < numberCheckboxes; i++) { checkBoxes[i] = new JCheckBox(); checkBoxes[i].setText("checkbox " + (i + 1)); checkBoxes[i].setBounds(5, (i + 2) * 25, 100, 30); checkBoxes[i].setSize(100, 30); checkBoxes[i].addActionListener(actionListener); checkBoxes[i].addChangeListener(changeListener); checkBoxes[i].addItemListener(itemListener); contentPane.add(checkBoxes[i]); } JButton btnOk = new JButton("OK"); btnOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(number); }}); btnOk.setBounds(343, 232, 89, 23); frame.getContentPane().add(btnOk); frame.setSize(450, 300); frame.setBounds(100, 100, 450, 300); frame.setVisible(true); }}
How do I cycle through an array of strings and display them one at a time when JButton is clicked   (105 Views)
all, I am a 42 year old computer science major but only two years in so I still have much to learn. I have pulled some strings from a text file and loaded them into an array. What is the best way to have each string displayed every time the next question button is pushed I am displaying it into a Text Field box, is this what would normally be used or is there a box better suited for this purpose I was planning on doing basically the same thing in the program with a file full of jpg's, but was hoping to make them display in the same window each time a new question was brought up. Any thoughts, suggestions, or flat out help would be appreciated,
Adding array list to JList - MVC - Getting nothing but memory addresses!   (85 Views)
I have an array list in a separate class called "Bottle" and a "View" class with a method called InitView. I have a contentpane that displays a JList and it populates the bottles memory addresses, but i need it to to populate the string version so it's readable... Any help would be greatly appreciated. VIEW CLASS package viewPackage; import java.awt.BorderLayout; public class View extends JFrame { static private JPanel contentPane; static ArrayList myBottles = new ArrayList(); private final JButton btnQuit = new JButton("Quit"); private final static JList list = new JList(); private static final String String = null; private final JLabel lblVendingMachineOptions = new JLabel("Vending Machine Options"); /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { InitSystem(); View frame = new View(); InitView(contentPane); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public View() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); btnQuit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); btnQuit.setBounds(335, 228, 89, 23); contentPane.add(btnQuit); list.setFont(new Font("Tahoma", Font.PLAIN, 15)); list.setBounds(28, 37, 221, 175); contentPane.add(list); lblVendingMachineOptions.setBounds(28, 22, 162, 14); contentPane.add(lblVendingMachineOptions); } private static void InitSystem() throws Exception{ Model myModel = new Model(); if (myModel.ConnectToDatabase()) { // Create an empty list of bottles myModel.ReadBottles(myBottles); } else { throw new Exception("View.InitSystem(): Unable to connect to database"); } } private static void InitView(JPanel contentPane) { DefaultListModel model = new DefaultListModel(); for(Bottle i:myBottles) { model.addElement(i.toString()); } list.setModel(model); list.setSelectedIndex(0); } }
Errors with array and JTextArea and ComboBox   (59 Views)
Hi all! I'm taking my first Java class (online) and have hit a huge wall trying to use swing for GUI elements. I would be extremely grateful is someone could look at my code and point me in the right direction for getting things working. This is my first post so I apologize if it is not formatted correctly. I am attempting to set up 2 arrays -- one to store an ID number that will display in a ComboBox and one to store votes assoicated with each ID number (I would love to do this with a single array if possible) -- and two text areas to display results, plus two buttons and a combobox. I've created private classes for the button and combobox listeners. I would like to increment the value stored in each array element when a vote is cast (vote button is pushed) and display a text chart of results when the end vote button pushed. Unfortunately, I am getting a null exception error whenever an array statement is encountered in the listeners. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class VoteControls extends JPanel { private final int MAX = 15; private final int MIN1 = 0; private final int MAX1 = 4; private final int MIN2 = 5; private final int MAX2 = 9; private final int MIN3 = 10; private final int MAX3 = 14; public JComboBox singersCombo; public JButton voteButton, endButton; public JTextArea textArea1, textArea2; public int singer = 0; public String[] singerID; public int[] singers; public Histogram chart; public String test; //constructor public VoteControls() { //create list of nums for singerID array String[] singerID = new String[MAX]; int [] singers = new int[MAX]; for (int i = 0; i < MAX; i++){ singerID[i] = Integer.toString(i); singers[i] = 0; System.out.println ("singers[" + i + "]: " + singers[i]); //display init check } //create Histogram object chart = new Histogram(MIN1, MIN2, MIN3, MAX1, MAX2, MAX3); //create combobox for singer IDs singersCombo = new JComboBox (singerID); singersCombo.setBackground(Color.white); //set up butons for voting voteButton = new JButton("Cast Vote"); voteButton.setBackground(Color.white); endButton = new JButton("End Voting"); endButton.setBackground(Color.white); //set up text areas textArea1 = new JTextArea(5,40); JScrollPane scrollPane = new JScrollPane(textArea1); textArea1.setEditable(false); textArea1.setBackground(Color.white); textArea2 = new JTextArea(5,40); JScrollPane scrollPane2 = new JScrollPane(textArea1); textArea2.setEditable(false); textArea2.setBackground(Color.white); //set up panel setPreferredSize(new Dimension(600,200)); setBackground(Color.cyan); add(singersCombo); add(voteButton); add(endButton); add(textArea1); add(textArea2); //set up listeners singersCombo.addActionListener(new ComboListener()); voteButton.addActionListener(new ButtonListener()); endButton.addActionListener(new ButtonListener()); } //****************** //action listener for combo box private class ComboListener implements ActionListener { public void actionPerformed(ActionEvent event) { singer = (Integer) singersCombo.getSelectedIndex(); textArea1.append("singer: " + Integer.toString(singer)); // just a test statement } } //********************** //action listener for buttons private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { if (event.getSource() == voteButton) { if ((singer >= 0) && (singer
how to add JButtons to an array   (79 Views)
Hi , I have a GUI i have created a gui qith 16 JButtons example of how i created them D3 = new JButton(""); D3.addMouseListener(mylistener); D3.setName("D3"); gbs.weightx = 0.02; gbs.gridx = 2; gbs.gridy = 3; gamePanel.add(D3, gbs); D4 = new JButton(""); D4.addMouseListener(mylistener); D4.setName("D4"); gbs.weightx = 0.02; gbs.gridx = 3; gbs.gridy = 3; gamePanel.add(D4, gbs);
Display an array in a swing type box   (74 Views)
Hi I am very new to Java. I am trying to create a swing display of a java keyword array that I have entered, but I'm not sure how to do so. The code so far is as follows: import javax.swing.*; public class SearchJavaReservedKeywordList { public static void main(String[] args) { //declarations String[] javaKeyword = {"", "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", " class", "const", "continue", "default", "do", "double", "else", "enum", "extends", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "void", "volatile", "while"}; String choiceString, keyword; int choice, x; boolean keywordWasFound = false; for(;;) { // Causes an infinite loop due to no (initialization; condition; iteration) being set in for choiceString = JOptionPane.showInputDialog(null, "Enter 1 to Search for Keyword, or 2 to display the full list (q to quit)", "Java Keyword search options", JOptionPane.QUESTION_MESSAGE); if((choiceString == "q") || (choiceString == "Q")) break; // breaks infinite loop choice = Integer.parseInt(choiceString); // Convert String to Integer for switch switch(choice) // switch selection statement { case 1: keyword = JOptionPane.showInputDialog(null, "Enter the word you would like to search " + "in the Java reserved keyword list", "Java Keyword search", JOptionPane.QUESTION_MESSAGE); for(x = 0; x < javaKeyword.length; ++x) if(keyword.equals(javaKeyword[x])) keywordWasFound = true; if(keywordWasFound) // Message box for unused keywords if(keyword.equals(javaKeyword[10]) || keyword.equals(javaKeyword[22])) JOptionPane.showMessageDialog(null, keyword + " is a Java reserved keyword, but it is currently not " + " used in Java programming.", "Search results", JOptionPane.INFORMATION_MESSAGE); else // Error message if box null if(keyword.equals(javaKeyword[0])) JOptionPane.showMessageDialog(null, "Please type a word before pressing" + " the enter key or clicking OK.", "Search results", JOptionPane.ERROR_MESSAGE); else //Message box if word is a reserved keyword JOptionPane.showMessageDialog(null, keyword + " is a Java reserved keyword.", "Search results", JOptionPane.INFORMATION_MESSAGE); else //Message box if word is not a Java reserved keyword JOptionPane.showMessageDialog(null, keyword + " was not found in the list of Java reserved Keyword.", "Search results", JOptionPane.INFORMATION_MESSAGE); break; case 2: // Display all keywords in array }//end switch } // end do-while loop } //end main()
converting a string color to an object color   (74 Views)
Would any one please shed a light. how to convert a String like: String colorStr = "Red"; to an Object
ImageJ, converting AWT to SWING   (59 Views)
For our Senior Design Project we are converting ImageJ's interface from AWT to SWING. The main problem is that we are not sure how to change MenuShortcut, or what the equivalent is in SWING. Any help would be greatly appreciated.
Suggestions on colour convertor program   (68 Views)
I want to write a program that maps the colours of a user-selected image to the closest matching colours in a given set. Here is the basic operation: -User opens an image using the program -The program checks the colour of each pixel in the image -For each pixel, the program chooses the closest matching colour from a set of eight colours (red, green, blue, cyan, magenta, yellow, white, black) -The program makes a new image from the 8 colours -The program displays the new image I have GUI programming experience in Java, but it's been some months since my last project (this is abit of a refresher). I am looking for is suggestions on how to proceed. For example, useful classes, good methods of implementation (should I go through pixel by pixel), etc.
How to create image from array of pixels?   (71 Views)
How to create image from array of pixels We can get pixels of an image from PixelGrabber. Is there any API which does reverse Create an image from array of pixels
Caching BufferedImages from byte[]   (51 Views)
I have a file containing serialized objects containing a byte[] representing a JPEG image. What I need to do is read through the file via ObjectInputStream to deserialize the object so that I can get the byte[] and then convert it to BufferedImage. The reason for doing this is due to the fact the a BufferedImage is not serializable so the JPEG image is serialized as byte[]. The reason for serializing the JPEG images into objects via OjectOutputStream is so that I can store some metadata for a particular frame and then display it as I am playing the sequence of images. (movie) The issue is converting a byte[] to BufferedImage costs time to process. For example: a 5000 by 5000 JPG image in byte[] to BufferedImage takes 0.3 seconds. This will results in a 2 frame by second play back. if I want to play it as 10 frames per second, I would need to get the byte[] to BufferedImage conversion down to at a minimum 0.1 seconds. If I was to process this at first or through some Thread, then I would need to store all of these processed images (BufferedImage) into memory. This would result in a JVM memory leak (OutOfMemory). The next option where I am stuck on is caching these BufferedImages. (approx 50,000 frames at 200k per frames) Is the a optimal caching soltion of these BufferedImages or is there a more optimal approach to serializing an object containing memtadata and byte[] (JPG image) and then streaming then as we read the file with a byte[] to BufferedImage conversion I am in need for some guidance or advice.
send arraylist to swings from servlet   (100 Views)
I send string to jsp from swings using URL And then call servet from jsp(submit some values to this servlet from jsp) Now i want to send ArrayList to my swings , How it is, i know call servlet from swings,retrive values from servlet to swings. This is two way communication, But now my requirement is one way, i didn't call servlet directly from swings, i call from jsp Help me,
Need to convert Console App to GUI...   (46 Views)
I need some examples of how to code a GUI input form for a console based application. I am in a time crunch which is why I am askin for examples at this time. I have been attempting (without great success) to go through the sun tutorials and some other text's as well and I have also pounded my head against the monitor going through the API, but I have to get this project done NOW and haven't coded in 2 years. I'm just looking for examples, not asking for anyone to do it for me.
chess game ;array_bug ;selection_of_pieces_in_chess_game   (56 Views)
hey ...i am making a project of "CHESS GAME"..... in which to identify any pieces of chess board ,i had used described mechanism....(see code of array) ... but it actually not takes garbage is working only for the "Rook"... i can't understand this please help me 2 find out d bugs.. you can also give some more efficient mechanism for identify the piece on chess board... if you know any thing which can help me to make chess game then please post it...hurry up!! thank you... mundvawala array code(jst for idea); jPieces = new String[8][8]; jPieces[0][0] = "bRook"; jPieces[0][1] = "bKnight"; jPieces[0][2] = "bBishop"; jPieces[0][3] = "bQueen"; jPieces[0][4] = "bKing"; jPieces[0][5] = "bBishop"; jPieces[0][6] = "bKnight"; jPieces[0][7] = "bRook"; jPieces[1][0] = "bPawn"; jPieces[1][1] = "bPawn"; jPieces[1][2] = "bPawn"; jPieces[1][3] = "bPawn"; jPieces[1][4] = "bPawn"; jPieces[1][5] = "bPawn"; jPieces[1][6] = "bPawn"; jPieces[1][7] = "bPawn"; jPieces[6][0] = "wPawn"; jPieces[6][1] = "wPawn"; jPieces[6][2] = "wPawn"; jPieces[6][3] = "wPawn"; jPieces[6][4] = "wPawn"; jPieces[6][5] = "wPawn"; jPieces[6][6] = "wPawn"; jPieces[6][7] = "wPawn"; jPieces[7][0] = "wRook"; jPieces[7][1] = "wKnight"; jPieces[7][2] = "wBishop"; jPieces[7][3] = "wQueen"; jPieces[7][4] = "wKing"; jPieces[7][5] = "wBishop"; jPieces[7][6] = "wKnight"; jPieces[7][7] = "wRook"; for(int x=0;x
How to convert Applet program into an Exe   (55 Views)
hi , I have created a Application in JApplet using swings.When i need to open the application i need to go to CMD and complie the program.I want to convert this application to an exe ,so that i can double click that and make the application to work. Could you please help me how to convert Applet Program into an Exe
Help me display array of JButtons properly   (90 Views)
Hi all... Im new to swing and I have a 2d array of JButtons...I'm trying to loop through the array and add them to the container but I dont understand how the layout managers work.So my 20x20 grid is being displayed something like 26x11...Could anyone provide a quick fix for the following code private static Tile[][] allTiles=new Tile[20][20] ; Container c=two.getContentPane();//two is a JPanel cont.setLayout(new GridLayout(20,20)); for(Tile[] tile :allTiles) { for(Tile t:tile) { two.add(t.tileButton); } }
ImageIO.write - TIF and BMP - Zero bytes   (78 Views)
I executed the code below from: import*; import java.awt.*; import java.awt.image.*; import javax.imageio.ImageIO; public class GenerateImageType { static public void main(String args[]) throws Exception { int width = 200, height = 180; BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bufferedImage.createGraphics(); Font font = new Font("Arial", Font.BOLD, 24); g2d.setFont(font); String text = "Welcome!"; FontMetrics fontMetrics = g2d.getFontMetrics(); int stringWidth = fontMetrics.stringWidth(text); int stringHeight = fontMetrics.getAscent(); g2d.setPaint(; g2d.drawString(text, (width - stringWidth) / 2, height / 2 + stringHeight / 4); ImageIO.write(bufferedImage, "gif", new File("C:\\image.GIF")); ImageIO.write(bufferedImage, "JPEG", new File("C:\\image.JPG")); ImageIO.write(bufferedImage, "PNG", new File("C:\\image.PNG")); ImageIO.write(bufferedImage, "BMP", new File("C:\\image.BMP")); ImageIO.write(bufferedImage, "TIF", new File("C:\\image.TIF")); } }
Nee Help!! JButton arrays action...   (56 Views)
Ok my first post here and a question!!Im working on a project for school and I ust cant seem to find a way to do this.....My teacher want Lotto 6/49 apllication (you have 49 numbers choose 6) so I made Jbutton array containing 49 problem is that the teacher want the JButton to setVisible(false) when its clicked (made it and work) and that 6 numbers appear in a JTextArea after selecting them and the button sta is set back to setVisible(true)....this is my Action code for now .... public void actionPerformed (ActionEvent ae ) { Object src = ae.getSource(); for(int i =0 ; i
mouse event for an array of object   (114 Views)
Is it possible add moseDragged event for an array of rectangle...