Build buttons/labels on a Displayed Image

Hi,
I have a small Java applet program that displays an Image.
I want to build buttons/labels/text on this Image. How do I do this?
Here is what I have so far:
import java .applet.Applet;
import javax.swing.*;
import java.awt.*;
public class Golf extends JApplet
private Image pic;
public void init()
pic = getImage(getDocumentBase(), ("GolfGif.gif"));
public void paint(Graphics g)
g.drawImage( pic, 0, 0, this);
Thanks
Regards
Geir

Hi
I want to develope an applet whit sirten buttons/labels etc, but I also want to show a picture as the background, how do I do this?
Seems to me what I have started on does not work, it must be other ways...
Thanks

Similar Messages

  • Button in mc to display image on main timeline

    I have a movie clip (mc_menu) that sits on the main timeline. Inside mc_menu I have several buttons that display items inside the mc. I also need to display an image on the main timeline. I have converted the image to a movie clip (mc_01). I am using AS2.

    My knowledge with AS is essentially non-existant. I added the following code on an actions layer in the movie clip (mc_menu):
    _root.attachMovie(mc_forecaster2_test);
    I do not have any code in the main timeline for this interaction.
    I tried to place the mc_forecaster2_test on the main timeline stage, and put in code to make the visible false, and code in mc_menu to make the visible true, but so far, nothing has worked.

  • Displaying image in gridview.

    Hi guys, i am trying to display a picture in a gird view on clicking the view button. no error was displayed, image was not displayed either. Help please!
    Code Behind
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
            Dim picture As ArrayList = New ArrayList()
            picture = Session("Picture")
            CType(GridView1.Rows(GridView1.SelectedIndex).FindControl("pictures"), Image).Visible = True
            CType(GridView1.Rows(GridView1.SelectedIndex).FindControl("pictures"), Image).ImageUrl = picture(GridView1.SelectedIndex)
            CType(GridView1.Rows(GridView1.SelectedIndex).FindControl("View"), Button).Text = picture(GridView1.SelectedIndex)
        End Sub
    web service code
    convert = oRecSet.Fields.Item("PicturName").Value
                        newHeaderRow("Picture") = "C:/Program Files/SAP/SAP Business One/Bitmaps/" + convert
    Thank You,
    Kean
    Edited by: kean tan on Jun 26, 2008 9:47 AM

    hi,
    Try this..... Set matrix column to it_PICTURE
    Dim oMatrix As SAPbouiCOM.IMatrix
    Dim oColumn As SAPbouiCOM.IColumn
    Dim oPic As SAPbouiCOM.IPictureBox
    oColumn = oMatrix.Columns.Add("picColumn", SAPbouiCOM.BoFormItemTypes.it_PICTURE)
    oPic = oColumn.Cells.Item(1).Specific ' <----
    the first cell of this column
    oPic.Picture = "d:\mypic1.bmp"
    oPic = oColumn.Cells.Item(2).Specific ' <----
    the second cell of this column
    oPic.Picture = "d:\mypic2.bmp"
    Regards,
    Puneeth S

  • How to add image as radio button label instead of text

    In a pure AS3 project, is there a way to add use an image placed in the library/ Flex/AIR SDK compiler path instead of text as a radio button label?
    I've tried substituting character may unicode like:
    rb1.label = String.fromCharCode("0x2592");
    But how this displays is dependent on the device, font character availability. Displays unpredictably.
    Would prefer anyway to use an image that I can create in AI.
    Any help appreciated.

    OK. I tried this, and it works.
    (Hopefully, the image will display in the same location, next to the radio button, on different devices.)
    Thank you.

  • Desperately seeking help for displaying image on button

    i wrote the following method to create and display a button with an icon, doesn't work and i cannot figure out what the problem might be and how to fix it, please help me...
    clo :))
    public static void addButton(Container c, String title,
    ActionListener listener)
    JButton button = new JButton(title);
    button.setBorder(null);
    button.setFocusPainted(false);
    button.setBorderPainted(false);
    button.setContentAreaFilled(false);
    ImageIcon icon = new ImageIcon("anImage.jpg");
    button.setIcon(icon);
    c.add(button);
    button.addActionListener(listener);
    the parameter c is of JPanel type and gets added to a JFrame object,
    the source compiles and runs but i see no image on my button, sigh :((!
    PS(the image file is placed in the same dir as the source file).

    Why buttons and labels might not show up the icon?
    Either your image is not in the classpath and you are trying to load it as a resource: see
    http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html
    or you are running the java machine from a different directory that you expect it does.
    or the file doesn't exist.
    To prove that the system cannot load the image use the example in the above link and the url will be null.
    URL iconURL = ClassLoader.getSystemResource("anImage.jpg");

  • Displaying image on the button

    hi there,
    well i wanna display image on my applet button from the relative path how do i do.
    here is my code which i tried gave me nullpointer exception and i did put this code my applets constructor:
    URL url1 = new URL(getDocumentBase().toString()+"b.gif");      
    ImageIcon image1 = new ImageIcon(url1);
    JButton button = new JButton(image1);

    SanderSander
    the code u have given failed to work well here is the code which i tried :
    ImageIcon image1 = new ImageIcon(getImage(getCodeBase(),"b.gif"));      
    JButton button = new JButton(image1);
    and here is the html code for applet :
    <!--"CONVERTED_APPLET"-->
    <!-- CONVERTER VERSION 1.3 -->
    <SCRIPT LANGUAGE="JavaScript"><!--
    var info = navigator.userAgent; var ns = false;
    var ie = (info.indexOf("MSIE") > 0 && info.indexOf("Win") > 0 && info.indexOf("Windows 3.1") < 0);
    //--></SCRIPT>
    <COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!--
    var ns = (navigator.appName.indexOf("Netscape") >= 0 && ((info.indexOf("Win") > 0 && info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0)));
    //--></SCRIPT></COMMENT>
    <SCRIPT LANGUAGE="JavaScript"><!--
    if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "500" HEIGHT = "300" codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"><NOEMBED><XMP>');
    else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.3" CODEBASE="http://192.168.1.50/paddy/ns/ns" CODE = "GPTextEditor" MAYSCRIPT="true" WIDTH = "500" HEIGHT = "300" scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED><XMP>');
    //--></SCRIPT>
    <APPLET CODE = "GPTextEditor" WIDTH = "500" HEIGHT = "300"></XMP>
    <PARAM NAME = CODE VALUE = "GPTextEditor" >
    <PARAM NAME = CODEBASE VALUE = "http://192.168.1.50/paddy/ns/ns" >
    <PARAM NAME=MAYSCRIPT VALUE=TRUE>
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
    <PARAM NAME="scriptable" VALUE="true">
    </APPLET>
    </NOEMBED></EMBED></OBJECT>
    i m using swing applet.....

  • Java Swing, Displaying Images in Labels

    Im rather new to java programming. Im finding it difficult to display images, as they never seem to appear when they should. When I downloaded the examples in the java tutorial (but not the picture files), changed the picture files to picture files I have in my computer, it also didn't display any pictures. My guess is that this is something to do with what the java tutorial said:
    "Generally, applications provide their own set of images used as part of the application, as is the case with the images used by many of our demos", and says that the createImageIcon() method should only be used when the images are part of the application. Could anyone explain to me how to make the set of images part of the application?
    When I tried using the new ImageIcon("") method also no picture appeared. Could anyone explain this to me as well?
    Sorry for bothering you all with such a probably trivial matter. Thank you :)

    It should, as far as I understand what you are describing. You have the bin directory, where you type "java <classname>" to start your app, and if the images are in that directory, all you should need is the filename. But generally, the image filename you use should be an absolute file path, or a path relative to the directory the application starts in.
    There are other ways, however, which might be more useful for applications, notably loaded as resource...
    new ImageIcon(getClass().getResource("xyz.gif"));
    Where xyz.gif is in an directory or Jar file in the classpath.

  • Special characters not displaying in button label

    My production environment is: Oracle Forms 6i connecting to an Oracle 8i database. Forms are Windows client/server. In a form there is a layout of buttons like a QWERTY keyboard. And in the property palette information for each data block, the item is of type "Push Button" and the default Label is set to a specific number which correlates to what that number translates into a special character (i.e. Portuguese, or Spanish characters). So example: CHR196 label = "196". So when at runtime. The following command is executing upon seeing this canvas:
    Set_Item_Property('CHR196', LABEL, CHR(196));
    So in Forms6i the CHR(196) comes out to be a letter in the alphabet from either Spanish or Portuguese and shows up perfectly.
    But NOT in 11g. That environment I'm in is:
    Oracle Fusion Middleware Forms 11g on RHEL5 (Red Hat Enterprise Linux version 5) on a 32-bit platform
    connecting to
    Oracle Database 11g on RHEL5 (Red Hat Enterprise Linux version 5) on a 64-bit platform
    using a
    Windows based browser (IE7 - Internet Explorer 7).
    Could it be due to the forms being in a JVM (Java Virtual Machine)? All I see is a small "square" and this shows up on ALL the button labels. Could it be the NLS_LANGUAGE format of the database? Because when I run the query : SELECT CHR(196) FROM dual on 8i or 11g, the proper character shows up in TOAD or SQL+.
    Thanks,

    Hello Paul,
    I once used hexadecimal coded characters like &xnnn; and they were not transformed. When coding them in decimal, everthing worked fine.
    Hth
    J�rg

  • How to create a report in Form line Style and can display Image field?

    Hi,
    In Report builder 10g, I would like to create a Report with Form Line Style and this report included a Image field.
    I can choose this Style only when Select Report type is Paper Layout. Because, If I choose Create both Web & Paper Layout or Create Web Layout only then in the next Style tab 03 option Form, Form letter and Mailing Label be Disabled.
    But in Paper Layout, my report can not display Image field.
    I tried with Web layout and all the other Styles (Except 03 mentioned be Disabled) then all Styles are displayed Imager field OK.
    How to create a report in Form line Style and can display Image field?
    I was change File Format property of my Image field from text to Image already in Property Inspector. But report only showed MM for my Image field.
    Thanks & regards,
    BACH
    Message was edited by:
    bachnp

    Here you go..Just follow these steps blindly and you are done.
    1) Create a year prompt with presentation variable as pv_year
    2) Create a report say Mid report with year column selected 3 times
    - Put a filter of pv_year presentation variable on first year column with a default value say @{pv_year}{2008}
    - Rename the second time column say YEAR+1 and change the fx to CAST(TIME_DIM."YEAR" AS INT)+1
    - Rename the second time column say YEAR-1 and change the fx to CAST(TIME_DIM."YEAR" AS INT)-1
    Now when you will run Mid Report, this will give you a records with value as 2008 2009 2007
    3) Create your main report with criteria as Year and Measure col
    - Change the fx for year column as CAST(TIME_DIM."YEAR" AS INT)
    - Now put a filter on year column with Filter based on results of another request and select these:
    Relationship = greater than or equal to any
    Saved Request = Browse Mid Report
    Use values in Column = YEAR-1
    - Again,put a filter on year column with Filter based on results of another request and select these:
    Relationship = less than or equal to any
    Saved Request = Browse Mid Report (incase it doesn't allow you to select then select any other request first and then select Mid Report)
    Use values in Column = YEAR+1
    This will select Year > = 2007 AND Year < = 2009. Hence the results will be for year 2007,2008,2009
    This will 100% work...
    http://i56.tinypic.com/wqosgw.jpg
    Cheers

  • Display image in view

    Hi,
    My requirement is to create a  web dynpro application where the first view contains all images stored in ECC along with one button (Display image). When the user clicks on the button Display image then another view should display the image on the screen.
    I have created View1 with a table,which display the details of the table STXBITMAPs in it,when i select a row and press a button second view is displayed with a UI conatiner of type IMAGE.
    Basiccaly when button on view1 is pressed, I get the value of the TDNAME field via lead_selection method and set this value to a global attribute, whch inturn is copied into second view and bonded to the SOURCE attribute of the UI element.
    My problem is , that global attribute is being updated probley and value have been passed to second view..but Image is not being displayed on the screen.
    Can anyone help me out in this.
    Thanks in advance.
    Pooja

    You don't necessarily have to move your images from STXBITMAPS to the MIME repository.  You can display any image - not just those in the MIME repository, by placing the content in the ICM Cache.  This creates a temporary URL for any content.  So you just need to read the binary content of the image from STXBITMAPS into a XSTRING variable.  From there you can use this code sample to put the content in the cache and generate a URL:
    ****Create the cached response object that we will insert our content into
      data: cached_response type ref to if_http_response.
      create object cached_response
        type
          cl_http_response
        exporting
          add_c_msg        = 1.
    *  cached_response->set_compression( options = cached_response->IF_HTTP_ENTITY~CO_COMPRESS_IN_ALL_CASES ).
    try. " ignore, if compression can not be switched on
          call method cached_response->set_compression
            exporting
              options = cached_response->co_compress_based_on_mime_type
            exceptions
              others  = 1.
        catch cx_root.
      endtry.
    ****set the data and the headers
      data: l_app_type type string.
      data: l_xstring type xstring.
          cached_response->set_data( me->gx_content ).
          l_app_type = 'image/x-ms-bmp'.
      cached_response->set_header_field( name  = if_http_header_fields=>content_type
                                         value = l_app_type ).
    ****Set the Response Status
      cached_response->set_status( code = 200 reason = 'OK' ).
    ****Set the Cache Timeout - 60 seconds - we only need this in the cache
    ****long enough to build the page and allow the IFrame on the Client to request it.
      cached_response->server_cache_expire_rel( expires_rel = i_cache_timeout ).
    ****Create a unique URL for the object
      data: guid type guid_32.
      call function 'GUID_CREATE'
        importing
          ev_guid_32 = guid.
      concatenate i_path '/' guid '.' i_format into r_url.
    ****Cache the URL
      cl_http_server=>server_cache_upload( url      = r_url
                                           response = cached_response ).

  • Displaying image from Database with php

    Hello everybody,
    I'm working on a website that displays videos courses and tutorials as my final project
    and I'm working with "Flash builder 4" the database with mySQL and the application server with php
    Basically, the goal is to display a datagrid that shows the manager of the website in column all the information stored on the "Course" table
    the structure of the table is :
    Course (id,img,src,title,description)
    -id : primary key
    -img : path to a photo of course {for example picture of JAVA}
    -src : path to the playlist file {xml file}
    -title : String
    -description : String too
    I already succeeded to display all these contents on a DataGrid, but not with the image, I couldn't display an imageon its column using the path stored on the database, I used a DataRenderer to do that, and here is my code for Renderer and the DataGrid.mxml
    CourseGrid.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:courseservice="services.courseservice.*">
    <fx:Script>
    <![CDATA[
    import Renderers.CourseDeleteRenderer;
    import Renderers.CourseImageRenderer;
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
    getAllCourseResult.token = courseService.getAllCourse();
    ]]>
    </fx:Script>
    <fx:Declarations>
    <s:CallResponder id="getAllCourseResult"/>
    <courseservice:CourseService id="courseService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <mx:DataGrid x="10" y="10" id="dataGrid"
    creationComplete="dataGrid_creationCompleteHandler(event)"
    dataProvider="{getAllCourseResult.lastResult}"
    width="100%">
    <mx:columns>
    <mx:DataGridColumn headerText="" dataField="img" sortable="false" itemRenderer="Renderers.CourseImageRenderer"/>
    <mx:DataGridColumn headerText="id" dataField="id"/>
    <mx:DataGridColumn headerText="src" dataField="src"/>
    <mx:DataGridColumn headerText="title" dataField="title"/>
    <mx:DataGridColumn headerText="description" dataField="description"/>
    <mx:DataGridColumn headerText="Delete" itemRenderer="Renderers.CourseDeleteRenderer"/>
    <mx:DataGridColumn headerText="Update" itemRenderer="Renderers.CourseUpdateRenderer"/>
    </mx:columns>
    </mx:DataGrid>
    </s:Application>
    CourseImageRenderer.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      focusEnabled="true">
    <mx:Image source="{data}" width="60" height="60"/>
    </s:MXDataGridItemRenderer>
    Result :
    Problem :
    How can I access to the path of the image, I tried to write "data.img" instead of "data" as img is the name of the column in the database that stores the path but it wasn't successful.
    I know that it not complete statement "data" because "data" is a reference to what the DataGrid provides of information that gets from the (CreationComplete) event.
    Question :
    - Can you please help me with this so I can complete displaying images by accessing to what is on the column in tha DB so I can manipulate my datas that is stored there ?
    ==> I still have some questions about the buttons to update and delete datas fomr the DataGrid, but, until now I need to access successfully to the photo and display it
    Thank you,

    Anyone that can help me with this ?
    Please, try this with me, I'm asking Flex developpers this might be easy for you !
    It's just question of how to access the string stored in the variable "data", when I used XML I just type the path to the repeated element like this :
    XML file :
    XML File
    <parent>
    <child>
    <repeated_child></repeated_child>
    <repeated_child></repeated_child>
    <repeated_child></repeated_child>
    </child>
    </parent>
    I used a Model as a reference to the xml file
    and an arrayList as a container of the repeated child
    I just write in the code "data.parent.repeated_child" to access the text in the "repeated_child"
    and here is the code, that I implemented to generate videos from xml file to display a video play list
    Video Playlist code(extract from XML file "data.xml")
    <fx:Declarations>
    <fx:Model id="model" source="assets/data.xml"/>
    <s:ArrayList id="products" source="{model.video}"/>
    </fx:Declarations>
    <mx:List  dataProvider="{products}" labelField="title"
      change="list1_changeHandler(event,List(event.currentTarget).selectedItem)" x="103" y="77" height="350" width="198"/>
    That was my goal to do that with the database.
    Please help me
    If you have other solution I still need it.
    Thank you,

  • Displaying image in a frame window using file dialog(using swing) ...

    here is my code....pls try running it...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class MainMenu3 extends JFrame {
    BorderLayout layout ;
    JPanel buttonPanel ;
    JFileChooser fileChooser ;
    JButton btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8;
    JMenuItem item1,item2,item3,item4,item5;
    JTextArea area;
    static private final String newline = "\n";
    JLabel label;
    public MainMenu3( ) {
    super("Image Processor");
    setSize(1024,740);
    setLocation(0, 0);
    layout= new BorderLayout(20,20);
    setLayout(layout);
    fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    // create the File menu
    JMenu file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);
    file.add(item1=new JMenuItem("New"));
    file.add(item2=new JMenuItem("Open"));
    file.addSeparator();
    file.add(item3=new JMenuItem("Save "));
    file.add(item4=new JMenuItem("Save As"));
    file.addSeparator();
    file.add(item5 = new JMenuItem("Quit"));
    // do some fancy stuff with the item
    item1.setMnemonic(KeyEvent.VK_N);
    item1.setAccelerator(
    KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
    item2.setMnemonic(KeyEvent.VK_O);
    item2.setAccelerator(
    KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
    item3.setMnemonic(KeyEvent.VK_S);
    item3.setAccelerator(
    KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
    item5.setMnemonic(KeyEvent.VK_Q);
    item5.setAccelerator(
    KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK));
    area=new JTextArea(10,10);
    //adding event listeners
    item2.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent e) {
    int result = fileChooser.showOpenDialog(null);
    File file1 = fileChooser.getSelectedFile();
    area.append("Attaching file: " + file1.getParent()+"\\"+file1.getName()
    + "." + newline);
    Image img = Toolkit.getDefaultToolkit().getImage(file1.getParent()+"\\"+file1.getName());
    item5.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    // create the Filter menu
    JMenu Filter = new JMenu("Filter");
    Filter.setMnemonic(KeyEvent.VK_I);
    Filter.add(new JMenuItem("Normal"));
    Filter.add(new JMenuItem("Blur"));
    Filter.add(new JMenuItem("Sharpen"));
    Filter.add(new JMenuItem("Invert"));
    Filter.add(new JMenuItem("Rotate"));
    Filter.add(new JMenuItem("GrayScale"));
    Filter.add(new JMenuItem("Colour"));
    // create the Help menu
    JMenu Help = new JMenu("Help");
    Help.setMnemonic(KeyEvent.VK_H);
    // create a menu bar and use it in this JFrame
    JMenuBar menuBar = new JMenuBar( );
    menuBar.add(file);
    menuBar.add(Filter);
    menuBar.add(Help);
    //setJMenuBar(menuBar);
    //creating buttons
    btn1=new JButton("Blur");
    btn1.setToolTipText("imparts blurredness to the image");
    btn2=new JButton("Sharpen");
    btn2.setToolTipText("sharpens the images outlines");
    btn3=new JButton("Invert");
    btn3.setToolTipText("inverts the image 180 degress ");
    btn4=new JButton("Rotate");
    btn4.setToolTipText("rotates the image by 90 degrees");
    btn5=new JButton("GrayScale");
    btn5.setToolTipText("imparts greyscale to the image");
    btn6=new JButton("Color");
    btn6.setToolTipText("color the image as desired");
    btn7=new JButton("Load");
    btn8=new JButton("Exit");
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(1,6,10,0));
    buttonPanel.add(btn1);
    buttonPanel.add(btn2);
    buttonPanel.add(btn3);
    buttonPanel.add(btn4);
    buttonPanel.add(btn5);
    buttonPanel.add(btn6);
    add(menuBar, BorderLayout.NORTH);
    add(btn7, BorderLayout.WEST);
    add(btn8, BorderLayout.EAST);
    add(area,BorderLayout.CENTER);
    add(buttonPanel,BorderLayout.SOUTH);
    public static void main(String[] args) {
    JFrame f = new MainMenu3( );
    f.addWindowListener(new WindowAdapter( ) {
    public void windowClosing(WindowEvent we) { System.exit(0); }
    f.setVisible(true);
    the code runs fine but d prob is.... i wnt is load a image in the area specified as Jtextarea(as i do not know the component on which the image is to be loaded,so i have just used it as a region to load the image)....pls help me to display an image in the specified region when i click on the "OPEN" option on the File Menu bar..

    here is my code....pls try running it...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class MainMenu3 extends JFrame {
    BorderLayout layout ;
    JPanel buttonPanel ;
    JFileChooser fileChooser ;
    JButton btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8;
    JMenuItem item1,item2,item3,item4,item5;
    JTextArea area;
    static private final String newline = "\n";
    JLabel label;
    public MainMenu3( ) {
    super("Image Processor");
    setSize(1024,740);
    setLocation(0, 0);
    layout= new BorderLayout(20,20);
    setLayout(layout);
    fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    // create the File menu
    JMenu file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);
    file.add(item1=new JMenuItem("New"));
    file.add(item2=new JMenuItem("Open"));
    file.addSeparator();
    file.add(item3=new JMenuItem("Save "));
    file.add(item4=new JMenuItem("Save As"));
    file.addSeparator();
    file.add(item5 = new JMenuItem("Quit"));
    // do some fancy stuff with the item
    item1.setMnemonic(KeyEvent.VK_N);
    item1.setAccelerator(
    KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
    item2.setMnemonic(KeyEvent.VK_O);
    item2.setAccelerator(
    KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
    item3.setMnemonic(KeyEvent.VK_S);
    item3.setAccelerator(
    KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
    item5.setMnemonic(KeyEvent.VK_Q);
    item5.setAccelerator(
    KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK));
    area=new JTextArea(10,10);
    //adding event listeners
    item2.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent e) {
    int result = fileChooser.showOpenDialog(null);
    File file1 = fileChooser.getSelectedFile();
    area.append("Attaching file: " + file1.getParent()+"\\"+file1.getName()
    + "." + newline);
    Image img = Toolkit.getDefaultToolkit().getImage(file1.getParent()+"\\"+file1.getName());
    item5.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    // create the Filter menu
    JMenu Filter = new JMenu("Filter");
    Filter.setMnemonic(KeyEvent.VK_I);
    Filter.add(new JMenuItem("Normal"));
    Filter.add(new JMenuItem("Blur"));
    Filter.add(new JMenuItem("Sharpen"));
    Filter.add(new JMenuItem("Invert"));
    Filter.add(new JMenuItem("Rotate"));
    Filter.add(new JMenuItem("GrayScale"));
    Filter.add(new JMenuItem("Colour"));
    // create the Help menu
    JMenu Help = new JMenu("Help");
    Help.setMnemonic(KeyEvent.VK_H);
    // create a menu bar and use it in this JFrame
    JMenuBar menuBar = new JMenuBar( );
    menuBar.add(file);
    menuBar.add(Filter);
    menuBar.add(Help);
    //setJMenuBar(menuBar);
    //creating buttons
    btn1=new JButton("Blur");
    btn1.setToolTipText("imparts blurredness to the image");
    btn2=new JButton("Sharpen");
    btn2.setToolTipText("sharpens the images outlines");
    btn3=new JButton("Invert");
    btn3.setToolTipText("inverts the image 180 degress ");
    btn4=new JButton("Rotate");
    btn4.setToolTipText("rotates the image by 90 degrees");
    btn5=new JButton("GrayScale");
    btn5.setToolTipText("imparts greyscale to the image");
    btn6=new JButton("Color");
    btn6.setToolTipText("color the image as desired");
    btn7=new JButton("Load");
    btn8=new JButton("Exit");
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(1,6,10,0));
    buttonPanel.add(btn1);
    buttonPanel.add(btn2);
    buttonPanel.add(btn3);
    buttonPanel.add(btn4);
    buttonPanel.add(btn5);
    buttonPanel.add(btn6);
    add(menuBar, BorderLayout.NORTH);
    add(btn7, BorderLayout.WEST);
    add(btn8, BorderLayout.EAST);
    add(area,BorderLayout.CENTER);
    add(buttonPanel,BorderLayout.SOUTH);
    public static void main(String[] args) {
    JFrame f = new MainMenu3( );
    f.addWindowListener(new WindowAdapter( ) {
    public void windowClosing(WindowEvent we) { System.exit(0); }
    f.setVisible(true);
    the code runs fine but d prob is.... i wnt is load a image in the area specified as Jtextarea(as i do not know the component on which the image is to be loaded,so i have just used it as a region to load the image)....pls help me to display an image in the specified region when i click on the "OPEN" option on the File Menu bar..

  • Air display Image problem

    I fetch an api service from a remote site, get a xml result,
    the format is below:
    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0">
    <channel>
    <item>
    <title>ssss....</title>
    <description><![CDATA[ssss....]]></description>
    <pubDate>Thu, 29 Jan 2009 05:38:39
    +0000</pubDate>
    <guid>
    http://fanfou.com/statuses/xxx</guid>
    <link>
    http://fanfou.com/statuses/xxx</link>
    </item>
    <item>
    <title>ttt....</title>
    <description><![CDATA[ttt....]]></description>
    <pubDate>Thu, 29 Jan 2009 05:36:09
    +0000</pubDate>
    <guid>
    http://fanfou.com/statuses/yyy</guid>
    <link>
    http://fanfou.com/statuses/yyy</link>
    </item>
    </channel>
    </rss>
    i will compute image url from this xml item and then i put
    the ArrayCollection in the the Repeater' DataProvider , as below:
    <mx:Image
    source="{getUsrImage(getUsr(String(rep.currentItem.title)))}"/>
    ## this image could display
    <mx:Repeater id="rep" horizontalCenter="true"
    verticalCenter="true" width="100%">
    <mx:HBox width="100%" horizontalAlign="center">
    <mx:Label
    text="{getUsr(String(rep.currentItem.title))}"/> ## this image
    could display
    <mx:Image
    source="{getUsrImage(getUsr(String(rep.currentItem.title)))}"/>
    ## this image could NOT display
    </mx:HBox>
    </mx:Repeater>
    Stange thing happened:
    if I run that in Flex Builder enviroment, all Image and Label
    could be displayed, but If i deploy to air and install it on
    windows or mac machine, only the label inside the repeater can
    display, also the image outside the repeater can display, but the
    Image control inside the Repeater can not display. it seems that
    any dynamic generate expression in source or tip property will
    cause the control not function.
    can anyone explains this to me, it puzzle me for a long
    time.

    I am also having an issue that is fine when testing in Flash
    but stops working when compiled and installed as an AIR app.
    This saves an image to the desktop..... but does nothing in
    AIR.
    public function Main():void
    var bitmapData:BitmapData = new BitmapData
    (stage.stageWidth, stage.stageHeight, true, 0x000000 );
    bitmapData.draw(this);
    var jpgEncoder:JPGEncoder = new JPGEncoder( 100 );
    var byteArray:ByteArray = jpgEncoder.encode( bitmapData );
    var filename:String = "IMAGE.jpg";
    var file:File = File.desktopDirectory.resolvePath( filename
    var wr:File = new File( file.nativePath );
    var stream:FileStream = new FileStream();
    stream.open( wr , FileMode.WRITE);
    stream.writeBytes ( byteArray, 0, byteArray.length );
    stream.close();
    }

  • Open and display image in MVC layout

    Hello!
    I cant figure out how I shall do this in an MVC layout:
    The program request user to open an image file that are then displayed in a JLabel
    My setup at the moment resolve in a nullpointerexeption because it dont get any actual image file, but I dont understand what I have missed.
    I can not post the whole code fo you to run because it is to big, so I post the part that are the most important. please have a look.
    PicturePanel
    //Import Java library
    import javax.swing.*;
    import java.awt.*;
    public class PicturePanel extends JPanel {
         //Variables
         private ImageIcon picture;
         //Method to get information of the selected file
         PicturePanel (String fileName) {
              picture = new ImageIcon (fileName); //Get the filename
              int w = picture.getIconWidth(); //Get the image with
              int h = picture.getIconHeight(); //Get the image height
              //Set preferable size for the image (Use the properties for the selected image)
              setPreferredSize(new Dimension(w, h));
              setMinimumSize(new Dimension(w, h));
              setMaximumSize(new Dimension(w, h));
         //Method to draw the selected image
         protected void paintComponent(Graphics g) {
              super.paintComponent(g); //We invoke super in order to: Paint the background, do custom painting.
              g.drawImage(picture.getImage(), 0, 0, this); //Draw the image at its natural state
    }From my model:
    //Local attributes
         boolean check = false; //Used to see if a statement is true or not
         PicturePanel pp;
         JFileChooser fc;
         int returnVal;
    //newFile in File menu
         public void newFile() {
              //Open a file dialog in users home catalog
              fc = new JFileChooser();
              //In response to a button click:
              returnVal = fc.showOpenDialog(pp);
              System.out.println("You pressed new in file menu");
         }From my controler:
    //User press "New" in File menu
              else if (user_action.equals("New")) {
                   //Call method in model class
                   model.newFile();
                   //Update changes
                   if (model.returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("Hello1");
                        File f = model.fc.getSelectedFile();
                        if (model.pp != null)     
                             model.pp = new PicturePanel(f.getAbsolutePath());
                        System.out.println("Hello2");
                        //Display image (Here is line 83)
                        view.setImage_DisplayArea(model.pp);
                        System.out.println("Hello3");
              }From my view:
    //Sets the image to be displayed on the image_display area (Here is line 302)
         public void setImage_DisplayArea(PicturePanel pp) {
              image_display.add(pp);
         }The complet error:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
         at java.awt.Container.addImpl(Container.java:1015)You pressed new in file menu
    Hello1
    Hello2
         at java.awt.Container.add(Container.java:351)
         at View_Inlupp2.setImage_DisplayArea(View_Inlupp2.java:302)
         at Control_Inlupp2.actionPerformed(Control_Inlupp2.java:83)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
         at javax.swing.AbstractButton.doClick(AbstractButton.java:334)
         at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1050)
         at apple.laf.CUIAquaMenuItem.doClick(CUIAquaMenuItem.java:119)
         at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1091)
         at java.awt.Component.processMouseEvent(Component.java:5602)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3129)
         at java.awt.Component.processEvent(Component.java:5367)
         at java.awt.Container.processEvent(Container.java:2010)
         at java.awt.Component.dispatchEventImpl(Component.java:4068)
         at java.awt.Container.dispatchEventImpl(Container.java:2068)
         at java.awt.Component.dispatchEvent(Component.java:3903)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
         at java.awt.Container.dispatchEventImpl(Container.java:2054)
         at java.awt.Window.dispatchEventImpl(Window.java:1801)
         at java.awt.Component.dispatchEvent(Component.java:3903)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)Edited by: onslow77 on Dec 16, 2009 5:00 PM
    Edited by: onslow77 on Dec 16, 2009 5:04 PM

    Hello again!
    Anyone that can help me figure out how to implement this in an MVC layout, I feel stuck.
    I post a little program that open and display an image file so that you better can understand what I whant to do.
    ShowImage
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import javax.swing.filechooser.*;
    public class ShowImage extends JFrame{
         //Variables
         JFileChooser fc = new JFileChooser();
         PicturePanel pp = null;
         ShowImage () {
              super("Show"); //Title
              //Create the GUI
              JPanel top = new JPanel();
              add(top, BorderLayout.NORTH);
              JButton openBtn = new JButton("Open");
              top.add(openBtn);
              openBtn.addActionListener(new Listner());
              //Settings for the GUI
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              pack();
              setVisible(true);
         class Listner implements ActionListener {
              public void actionPerformed(ActionEvent ave) {
                   int answer = fc.showOpenDialog(ShowImage.this);
                   if (answer == JFileChooser.APPROVE_OPTION){
                        File f = fc.getSelectedFile();
                        //Check
                        System.out.println(f);
                        System.out.println(pp);
                        if (pp != null)
                             remove(pp); //Clean so that we can open another image
                        //Check
                        System.out.println(pp);
                        //Set the PicturePanel
                        pp = new PicturePanel(f.getAbsolutePath());
                        //Check
                        System.out.println(pp);
                        //Add PicturePanel to frame
                        add(pp, BorderLayout.CENTER);
                        validate();
                        pack();
                        repaint();
         //Main
         public static void main(String[] args) {
              new ShowImage();
    }PicturePanel
    //Import Java library
    import javax.swing.*;
    import java.awt.*;
    public class PicturePanel extends JPanel {
         //Variables
         private ImageIcon picture;
         //Method to get information of the selected file
         PicturePanel (String fileName) {
              picture = new ImageIcon (fileName); //Get the filename
              int w = picture.getIconWidth(); //Get the image with
              int h = picture.getIconHeight(); //Get the image height
              //Set preferable size for the image (Use the properties for the selected image)
              setPreferredSize(new Dimension(w, h));
              setMinimumSize(new Dimension(w, h));
              setMaximumSize(new Dimension(w, h));
         //Method to draw the selected image
         protected void paintComponent(Graphics g) {
              super.paintComponent(g); //We invoke super in order to: Paint the background, do custom painting.
              g.drawImage(picture.getImage(), 0, 0, this); //Draw the image at its natural state
    }//The endEdited by: onslow77 on Dec 16, 2009 7:30 PM

  • Problem Displaying Images in a JFrame

    I am writing a program that displays images on a JFrame window. I have been reading the other postings about this topic however I have not been able to make my code work. I am hoping there is some obvious solution that I am not noticing. Please help, I am very confused!
    public class WelcomeWindow {
    private JLabel label;
    private ImageIcon logo;
    public WelcomeWindow() {
    label = new JLabel();
    logo = new ImageIcon("/images/logo.gif");
    label.setIcon(logo);
    this.getContentPane().add(label);

    Instead of a JLabel, have you tried to use a JButton containing the Icon?
    Also (but I think you've done it already), you could do that :
    File iconFile = new File("/images/logo.gif");
    if (!iconFile.isFile()) {
    System.out.println("Not a file");
    That way you'll be certain that the path given is correct.
    Hope this helps.

Maybe you are looking for

  • Safari 3.0.4 misbehaving

    Hi, I use a content management system, for the website I run, that is accessed over the internet. As the system was set up to run on Internet explorer there have always been little problems using the system on a mac but most of these were ironed out

  • COGI - Diference between Error date, Creation date & posting date

    Hi All, While running COGI report, I could see columns " Creation Date" , "Error Date", But I could not get the meaning of this fields from the F1 Help.  could anuone of you please help me with the relevancy of these columns. Also the Posting date so

  • Please help my flv video file works perfectly localy...but its not visible in remote ftp why??

    hi All, Please help me. my flv video file works perfectly localy in my computer...but its not visible when i uploaded the flv html and flash files to ftp? thanks in advance

  • How to hide pm shop paper keys in order which is not required.

    Dear All, I have created one b/d maintenance order which is released, now I have to take a print out of shop papers. For this I have ref. following menu path through IW32 transaction Order>Print>Order Then one window will get pop up u201Cselect shop

  • Where can I download ECC trial for self use?

    Hi. 1. I want to download ecc 6.0 trial version or vmware for testing.     where can I download?     As I remember, it can be download in sap site, but now I can't find. 2. I downloaded netweaver 7.1 trial, but it has no functionality and can not use