Select () in java

Hi,
I'm new to socket in java and dunno if there is a mechanism which is similar to using the select () system call in unix ? What I mean is that how can we know there are some data to read from a socket ?
Thanx a lot to any one that can help me.

The read method of the InputStream class will hang forever until data is available or an error occurs. If you want select() timeout type functionality, use the Socket.setSoTimeout(int millis) method before each read() call.
while(true)
  // without this, the read will hang forever
  socket.setSoTimeout(10 * 1000);
  r = aReader.read();
}You know data is available when the read call returns or times out.

Similar Messages

  • Case Selection in java

    for multi-selections, is there Case Selection statement in java?
    can anyone help? thanks

    Your question is a little vague, but I suppose you mean something like this:
    int i = ...;
    switch (i) {
      case 2:
      case 4:
      case 7:
        System.out.println("i is 2, 4 or 7");
        break;
      case 5:
      case 3:
        System.out.println("i is 5 or 3");
        break;
      default:
        System.out.println("i is something else");
        break;Jesper

  • Jpql - multi expressions in select query, java.lang.ClassCastException:

    Hello, i'm trying to get a Unit object from the query below.
    i am getting javax.ejb.EJBException in this method
    @NamedQuery(name = "getUnitIdUnitName", query = "SELECT u.unitId,u.unitName FROM Unit u "+ "ORDER BY u.unitName")
    public Unit getUnitsComboBox() {
    //get UnitId, UnitName from Units.
    Unit unitIDUnitName =(Unit) ((List<Object[]>)em.createNamedQuery("getUnitIdUnitName").getResultList()).get(0)[0];
    return unitIDUnitName;
    Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to mmis.entity.Unit
    Must i use an iterator ?
    Thanx

    Amasoni wrote:
    Hello, i'm trying to get a Unit object from the query below.
    i am getting javax.ejb.EJBException in this method
    @NamedQuery(name = "getUnitIdUnitName", query = "SELECT u.unitId,u.unitName FROM Unit u "+ "ORDER BY u.unitName")
    public Unit getUnitsComboBox() {
    //get UnitId, UnitName from Units.
    Unit unitIDUnitName =(Unit) ((List<Object[]>)em.createNamedQuery("getUnitIdUnitName").getResultList()).get(0)[0];
    return unitIDUnitName;
    Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to mmis.entity.Unit
    ThanxYou don't want to select the columns, you want to select the object itself.
    SELECT u FROM Unit u ORDER BY u.unitName
    or even shorter:
    FROM Unit u ORDER BY u.unitName
    Try to reason where to put your question by the way, it is not about Javaserver Faces. If you can't find a forum that clearly matches consider putting it in Java Programming. In this case it was entirely unnecessary since you already posted JPA questions in the EJB forum, which is a decent match.

  • Selection in java tools

    Hi, I have installed PI 7.0 SPS16 on hp-ux 11.31 ia64. Java version is 1.4.2.19.
    When using Web tools like RWB Message monitor or Communication Channel monitor
    I can not see what items I already selected or in other words: the radio buttons for selection in the first column are not visible.
    Any suggestion why is that? Is this mainly a java or a sap problem?
    Thanks,
    Janos

    Hi Janos,
    I doubt that the problem would be because of the Java version.
    As per the [Product Availability Matrix |https://websmp105.sap-ag.de/~form/handler?_APP=00200682500000001303&_EVENT=RELEASE&00200682500000002804=01200615320900001250&00200682500000003818=JSEPFM&00200682500000003853=Process%20Integration%20(PI/XI)] you need to use JSE 1.4.2 64 Bit for HP-UX 11.31 ia64.
    You can find the download link in the SAP note 941595.
    Note: 941595
    Symptom
    Download Java 2 SDK, Standard Edition x64 1.4.2
    Other terms
    Java, JVM J2SE, AMD64, x86_64, JDK Windows x64
    Reason and Prerequisites
    Customers would like to download Java 1.4.2 for the x64 platform
    Solution
    The Java 2 SDK, Standard Edition x64 1.4.2 can be obtained from
    the following location:
    http://java.sun.com/j2se/1.4.2/SAPsite/download.html
    Please note:
    - This version of the J2SE 1.4.2 SDK is strictly for use
    by SAP customers along with SAP software products. You will need a Sun
    Online Account (Registration is free and can be performed on the web
    page to which the download link points).
    - There is no need to uninstall any other (newer) Java software that may
    be installed on your server.
    - Any support requests should be directed to SAP support channels.
    Install the version J2SE 1.4.2_18 or 17 and let us know the progression.
    Thanks
    SaNv...

  • Tech Usuage Selection for Java Related components

    Hi,
    This is related to the Technical Usuage selections in the solution
    manager.
    We are currently going for an upgrade from R/3 4.6C system to ECC 6 -
    EHP4. We need to have the Technical usuages like "Biller Direct -
    FSCM", Portal Content Common, Standard XI content..etc to be installed
    along with our upgrade.
    When we select the tech usuages from the tcode solution_manager...etc.,
    Solution manager doesn't allow us to select Biller Direct bcos
    there is * mark near SAP FSCM - Biller Direct which says there is no
    Java system.
    Since 4.6C is not a java system its not allowing us to download the
    same.
    But our customer wants to install the ones which is mentioned above as
    part of our upgrade,
    Can u pl let us know how to select/install technical usuages like
    Biller Direct, Portal Contect.. (which are Java Dependencies) along
    with our upgrade from 4.6C to ECC 6.0
    Thank you in advance
    Thanks & Regards
    Senthil

    Hi,
    If portal is not there in your system then how will you download these patches..
    Because to download patches you have to register Java stack in SMSY in solman. If you will not register it then MOPZ will not allow you to download these patches.
    Thanks
    Sunny

  • Selective updating Java Installations?

    Looking for a way to selectively update certain java runtimes on a system...
    As part of our base build we have java installed, which we update after testing. Unfortunately, many other products install their own versions in proprietary locations as many of us know. I'm looking for a solution where I can keep my build's java from auto-updating and selectively have products with java installed in other locations automatically update so we don't have to worry about them...but not all of them since some products won't support a higher version and we have to just accept that risk.
    Can the deployment configuration file and properties file be used to do this? Is there an automated way we can add this type of selection via script? Can we standup a webserver for systems to download our latest approved version instead of going to Sun?
    Many thanks in advance!

    Looking for a way to selectively update certain java runtimes on a system...
    As part of our base build we have java installed, which we update after testing. Unfortunately, many other products install their own versions in proprietary locations as many of us know. I'm looking for a solution where I can keep my build's java from auto-updating and selectively have products with java installed in other locations automatically update so we don't have to worry about them...but not all of them since some products won't support a higher version and we have to just accept that risk.
    Can the deployment configuration file and properties file be used to do this? Is there an automated way we can add this type of selection via script? Can we standup a webserver for systems to download our latest approved version instead of going to Sun?
    Many thanks in advance!

  • Need general advice on package selection regarding java

    Hi,
    I have done a course in programming and covered some of the many areas of java ..... Since finishing that course I have been on and off java . I have used jbuilder9 and also briefly used some other IDEs. Anyway in the past I have done some simplistic graphics programming such as a ball bouncing across the screen. The thing is im planning on writing a small snooker or pool game , Im really determined and I want it to be a structured learning experience ....where Im using objects,interfaces and such. The thing is ....in college the graphical aspects of a program never stretched much beyond using what is provided by the jbuilder IDE. What I want to do is build a pool game but use my own classes and interfaces where appropriate and I was wandering what the best way to do it would be? .....Its a kind of general question so I will try and elaborate....Im willing to get into the ins and outs of understanding the code its just that Im not so sure jbuilder is the correct software to use for this kind of thing, especially with the fact that I want my code to 100% be my own .....e.g NO or very little auto generated stuff. Doing it this way will probably be inefficient but I feel I will grasp javas many complexities by having less "Bells & Whistles" so to speak :-) .....I want to do everything from creating an initial background frame to coding a class ball for the pool balls and somehow dealing with all the angles that a ball can be hit from.
    Is there any sites anyone could recommend that cover the coding of a java game from scratch ......and also uses the functionality of java by immplementing interfaces , classes and explaining there purpose as they go?
    Also a site with an install guide for whatever software is recommended would be great :-)
    I was going to use netbeans 4.0 buy when I click for documentation on an error it says something about "cannot find javadoc documentation. check platform manager to make sure the documentation is added" .......you see I am used to being able to click on an error and get a whole wealth of information about that error or relevant tutorials(such as in jbuilder.....I want good instant error documentation like this).
    Any help would be greatly appreciated.......also bearing in mind that I want to be able to use my own code without having to understand an ide inside out.......although I want to use one all the same .....:-)
    David

    Is there any sites anyone could recommend that cover
    the coding of a java game from scratch ......and also
    uses the functionality of java by immplementing
    interfaces , classes and explaining there purpose as
    they go?I belive there is a nice tutorial on here, and several if you google, but there is a very good listing in the Java Games Developement forum--this subject comes up there often. There are also listing of 3rd party packages that will help with vaious tasks, such as, graphics.
    Also a site with an install guide for whatever
    software is recommended would be great :-)Install guides are generally supported by the specific tool you wish to use.
    I was going to use netbeans 4.0 buy when I click for
    documentation on an error it says something about
    "cannot find javadoc documentation. check platform
    manager to make sure the documentation is added"
    .......you see I am used to being able to click on an
    error and get a whole wealth of information about
    that error or relevant tutorials(such as in
    jbuilder.....I want good instant error documentation
    like this). for netbeans you need to install the Java Docs seperate.
    Any help would be greatly appreciated.......also
    bearing in mind that I want to be able to use my own
    code without having to understand an ide inside
    out.......although I want to use one all the sameI use NetBeans and find it does as well as most others I've tried--especially the free ones. There are several to meet your tastes and preferences, i always recomend try a few and see what you like. For a list of IDE's do a search in this forum, the topic comes up several times a year.

  • What is the parallel command to select in Java?

    I mean if 2 or more process try to connect me how can I accept them all?

    I mean if 2 or more process try to connect me how can
    I accept them all?Normally you have a thread that reads and puts messages in a queue. Then one or more other threads pull messages from the queue and process them.
    If however, you really want the select() idiom then you need to look at the nio package. (And search the site for a particularly nice long post which provides an example on using it.)

  • Selecting between java.io and java.nio

    Hi,
    I'm a bit confused between java.io and java.nio. What sre the major differences between these two?
    In areas are these best applicable?

    The java.nio package improves on the basic Java I/O that was available prior to JDK 1.4.
    It is designed to interoperate more natively with the underlying file handles (sockets, open files etc) to achieve better performance.
    The improvements include true non-blocking I/O, better buffer management, character-set support, channels (similar to Occam's channels) and selectors, and some other ancillery stuff. Most of these classes are designed to be inherently threadsafe.
    There are some examples here:
    http://java.sun.com/j2se/1.4.2/docs/guide/nio/example/index.html
    However, if you are still a beginner with file or network I/O, its better if you start with the simple I/O first. You'll appreciate the NIO improvements better afterwards.

  • SELECT returning different rows when issued from SQL Developer or Java apps

    Hi there. I'm facing a problem here: I'm trying to issue a SELECT from Java, which should return me 2 rows; but I'm getting just one. When I issue the SELECT directly through SQL Developer it gives me the expected result. I've pastebin the code at http://paste.uni.cc/11821, where I've described in details the problem.
    What could it be? Any help would be appreciated.
    Thanks in advance!

    Marco,
    I would code it a bit differently, but I don't think that would solve your problem.
    I suggest setting up the JDBC logging. I'm not promising it will help, but I guess it
    can't hurt. Here is a white paper about it:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/pdf/logging%20white%20paper.pdf
    You can also access that link from this Web page:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
    Good Luck,
    Avi.

  • How to Get Current Date from MS Access in a Select Statement

    From a java method, I want to use JDBC to get the current date from MS Access. In Oracle I would do "select sysdate from dual", but I can't figure out how to do it in MS Access. Here are some of my attempts. I have a table in my Access db called PARM.
    //        String sql = "SELECT '0', NOW() FROM PARM";
    //rs.next() is false
    //        String sql = "SELECT NOW() AS CURR_DT FROM PARM";
    //rs.next() is false
    //        String sql = "SELECT DATE() AS CURR_DT FROM PARM";
    //rs.next() is false
    //        String sql = "SELECT NOW()"; 
    //StringIndexOutOfBoundsException: String index out of range: -1
    //        String sql = "select { fn now() } from parm";
            String sql = "SELECT Date()";
    //java.lang.StringIndexOutOfBoundsException: String index out of range: -1
            ResultSet rs = stmt.executeQuery(sql);
            if (rs.next()) {
                return rs.getString(1);
            } else {
                   return null;
              }

    Why are you getting it as a String? You should be getting it as a timestamp.
    Although getString works for me too. There is something else wrong that you haven't shown.
    Here is some shoddy, but simple, test code that demonstrates it working.
    import java.sql.*;
    public class Test{
      public static void main(String args[])throws Exception{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection c = DriverManager.getConnection("jdbc:odbc:stats");
        Statement s = c.createStatement();
        ResultSet rs = s.executeQuery("SELECT NOW()");
        while(rs.next()){
          System.out.println(rs.getTimestamp(1));     
        rs.close();
        s.close();
        c.close();
    }

  • Java issue with web analysis

    Hi,
    Web analysis is taking too long to start on client machines. I had this issue a couple of years ago with java 1.4.10. hyperion came back with a solution to increase the memory java uses on both the server and the client.
    »Xms128m -Xmx256m -Xss2m » in the Java plug-in (Control Panel>Java plug-in>Advanced)
    I cannot see on java 1.5.11 how to add this in. Java 1.5 was meant to make web analysis faster. In some environments it has but in this partilcuar case web analysis is very slow.
    I would appreciate it if anyone could suggest a way to make web analysis faster.
    The server environment is unix. Can a cache setting be added to java?
    The client issue is the most pressing one.
    Thanks in advance,
    Nathan

    Hi,
    Go to Java Control Panel, select the Java tab. You'll see Java Applet Runtime Settings section. Click View and fill the Runtime Parameter with your settings.
    HTH,
    Gerd

  • WDVisibility type paramter in Java Bean(Web Dynpro DC in CE 7.1)

    Hi All,
    I need to set a WDVisibility type paramter in a java bean and i am able to do so.It imports com.sap.tc.webdynpro.progmodel.api.WDVisibility class .
    The problem is when i am creating a Java Bean model  it is not allowing me to select the Java bean class it gives an error message" Invalid Class : No class files found for JavaBean : com/sap/tc/webdynpro/progmodel/api/WDVisibility".
    The java Bean class exists in Web Dynpro DC>src folder.
    Any Pointers?
    Regards
    Avinash

    Hi Ondrej ,
    Refer the above links to convert the component of the first dc as a public part.
    Then declare the methods which are written in the component controller of the first DC in the interface controller with the same signature.( When method is called automatically component controller method is called)
    In second dc in component controller properties tab add the reference of the first dc.
    Then access the method in second dc as
    wdthis.wdget<UsedComponent name>Interface.methodname();
    Thanks & Regards,
    Ardhendu

  • Behaviour of AXIS with Spring and Java, in response to bad webservice call

    This is a stretch, but I wonder if you can help me - I'm new to this, and working in a project that has already been configured to work with Axis.
    We have a Java project built with the Spring framework, in order to provide webservices for access via SOAP. As I understand it (ie not very well!) Axis works to accept these SOAP messages from the client and transform them into calls on our Java methods, and do the reverse with the responses - cool! Which is excellent, and it works well with the config files we have already set up.
    But I have two problems/questions, which may well be related�
    2) In trying to test what exactly happens in which case, I sent some test messages to the service, and found that I could send incorrect parameter names, and sometimes the service still gets called! Axis seems to match the data it recieves to the parameters of the method in some clever way that I don�t understand. Sometimes this works, sometimes it shows a type error. But it seems to depend what parameter I rename as to what exactly happens, so the results are (superficially, at least) unpredictable! I'm sure this behaviour is configurable in some way, but I can't seem to find out how this is done. I'd like to make it so that missing parameters are passed into the method as nulls (as is happening now), but that badly named, duplicated or extraneous parameters are refused, with a specific errormessage stating what the issue is. Similarly, I'd like to reply with an explanatory message if a parameter is passed wth an incorrect type, rather than just a message "org.xml.sax.SAXException: Bad types" that does not detail which parameter is problematic.
    1) The client can receive a "500" response, with an "Internal Server Error" message, although I'm having trouble figuring out exactly when this happens. I'd like to be able to configure what message they receive, in order to give them more information about what they got wrong.
    I just don't know where to start with this - I'm sure there must be ways of configuring all this!
    As much info about an example of what I'm looking at as seems sensible follows. Please forgive me if I've used incorrect terminology somewhere! :)
    Thanks a heap,
    Tracey
    ======================
    So, let's say I have a Java class called DiaryService, with a method called createDiary that takes the appropriate data and returns a confirmation/error message - it starts like this :
        public String createDiary(final String library,
                final BigDecimal companyCode, final Date diaryDate,  final Date actionedDate,
         final String diaryMessage) throws RemoteException And another called GetDiary that returns a Diary as a SOAP bean which looks like this :
        public DiarySoapBean getDiary(final String library,
                final BigDecimal companyCode, final Date diaryDate) throws RemoteExceptionAxis very helpfully lets me access the createDiary and getDiary, by sending XML messages like this example:
    <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <ns1:createDiary soapenc:root="1" xmlns:ns1="http://localhost:8080/morph_zta/services/DiaryService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
    <library xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">ZRMORPHTA</library>
    <companyCode xsi:type="xsd:Decimal" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">1</companyCode>
    <diaryDate xsi:type="xsd:date" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">2007-01-01Z</diaryDate>
    <actionedDate xsi:type="xsd:date" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">2007-01-01Z</actionedDate>
    <diaryMessage xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"/>Blah blah blah</diaryMessage>
    </ns1:createDiary>
    </soapenv:Body>If I rename a parameter, the service may get called, with some other data in that parameter or not, or may not get called at all and the user get a "SAXException: Bad types" error message. I would like it to return a message stating that the parameter is not expected.
    If I duplicate a parameter, the first occurrence appears to be used, and the next ignored. I would like it to return a message saying tnat the extra parameter is not expected.
    If I add gibberish parameters, I get a "No such operation" message. I would like to be able to tell which parameters are incorrect.
    We have entries like this in web.xml:
        <listener>
            <listener-class>
                   org.apache.axis.transport.http.AxisHTTPSessionListener
         </listener-class>
        </listener>
        <servlet>
            <display-name>Apache-Axis Servlet</display-name>
            <servlet-name>axis</servlet-name>
            <servlet-class>
                   com.workingmouse.webservice.axis.SpringAxisServlet
         </servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>axis</servlet-name>
            <url-pattern>/servlet/AxisServlet</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>axis</servlet-name>
            <url-pattern>*.jws</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>axis</servlet-name>
            <url-pattern>/services/*</url-pattern>
        </servlet-mapping>     And these bits in our server-config.wsdd :
        <!-- Global config options -->
        <globalConfiguration>
            <parameter name="adminPassword" value="admin"/>
            <parameter name="attachments.Directory" value="./attachments"/>
            <parameter name="attachments.implementation"
                    value="org.apache.axis.attachments.AttachmentsImpl"/>
            <parameter name="sendXsiTypes" value="true"/>
            <parameter name="sendMultiRefs" value="true"/>
            <parameter name="sendXMLDeclaration" value="true"/>
            <parameter name="axis.sendMinimizedElements" value="true"/>
            <requestFlow>
                <handler type="java:org.apache.axis.handlers.JWSHandler">
                    <parameter name="scope" value="session"/>
                </handler>
                <handler type="java:org.apache.axis.handlers.JWSHandler">
                    <parameter name="scope" value="request"/>
                    <parameter name="extension" value=".jwr"/>
                </handler>
        <handler name="acegiAuthenticationHandler" type="java:{our}.AcegiAuthenticationHandler"/>
            </requestFlow>
         <responseFlow>
              <handler name="OutgoingSOAPMessageViewer" type="java:{our}.OutgoingSOAPMessageViewer"/>
         </responseFlow>
        </globalConfiguration>
        <!-- Handlers -->
        <handler name="LocalResponder"
                type="java:org.apache.axis.transport.local.LocalResponder"/>
        <handler name="URLMapper"
                type="java:org.apache.axis.handlers.http.URLMapper"/>
        <handler name="Authenticate"
                type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
        <!-- Axis services -->
        <service name="AdminService" provider="java:MSG">
            <parameter name="allowedMethods" value="AdminService"/>
            <parameter name="enableRemoteAdmin" value="true"/>
            <parameter name="className" value="org.apache.axis.utils.Admin"/>
            <namespace>http://xml.apache.org/axis/wsdd/</namespace>
        </service>
        <service name="Version" provider="java:RPC">
            <parameter name="allowedMethods" value="getVersion"/>
            <parameter name="className" value="org.apache.axis.Version"/>
        </service>
        <!-- Global config options -->
        <transport name="http">
            <requestFlow>
                <handler type="URLMapper"/>
                <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
            </requestFlow>
        </transport>
        <transport name="local">
            <responseFlow>
                <handler type="LocalResponder"/>
            </responseFlow>
        </transport>
        <service name="DiaryServices" provider="Handler" style="rpc">
            <parameter name="handlerClass" value="com.workingmouse.webservice.axis.SpringBeanRPCProvider"/>
            <parameter name="springBean" value="diaryServices"/>
            <parameter name="springBeanClass" value="uk.co.trisystems.morph.ta.diary.soap.DiaryService"/>
            <parameter name="allowedMethods" value="createDiary getDiary"/>
            <parameter name="scope" value="application"/>
            <beanMapping qname="ns:diary" xmlns:ns="urn:DiaryService" languageSpecificType="java:uk.co.trisystems.morph.ta.diary.soap.DiarySoapBean"/>
        </service>Cheers
    Tracey Annison

    Hi,
    I have solved the problem, I forgot a parameter in the select, so java tells the an error. But now I have another problem. The procedure doesn't execute the order by. I pass the couple column_name order_type in a string as ("provider_description desc") dinamically but the procedure doesn't execute the ordering. Why?
    Thanks, bye bye.

  • Problem with JMenus that Persist - Is this a Java bug?

    I am having a problem with JMenus that persist. By this I mean
    that my drop down menus persist on the screen even after they have
    been selected.
    I've checked the Java bug database, and the following seems
    to come closest to my problem:
    Bug ID: 4235188
    JPopupMenus and JMenus persist when their JFrame becomes visible
    State: Closed, not a bug
    http://developer.java.sun.com/developer/bugParade/bugs/4235188.html
    This page says that the matter is closed and is not a bug. The
    resolution of this matter printed at the bottom of the page
    is completely abstruse to me and I would appreciate any
    comments to understand what they are talking about.
    The code at the end of my message illustrates my problem.
    1. Why should paintComponent() make any difference to
    Menu behavior?
    2. Is this a bug?
    3. What's the workaround if I have to paint() or repaint()?
    Thanks
    Tony Lin
    // Example of Menu Persistence Problem
    // Try running this with line 41, paintComponent(), and without line 41
    // Menus behave normally if line 41 is commented out
    // If line 41 exists, menus will persist after they have been selected
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class P2 extends JPanel {
    JMenuItem[] mi;
    public P2() {
    JFrame thisFrame = new JFrame();
    thisFrame.getContentPane().add(this);
    JMenu menu = new JMenu("My Menu");
    JMenuBar mb = new JMenuBar();
    mi = new JMenuItem[4];
    for (int i=0; i<mi.length; i++) {
    mi[i] = new JMenuItem("Menu Item " + String.valueOf(i));
    menu.add(mi);
    mb.add(menu);
    thisFrame.setJMenuBar(mb);
    thisFrame.setSize(400,200);
    thisFrame.setLocation(150,200);
    thisFrame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    System.exit(0);
    thisFrame.setVisible(true);
    public void paintComponent(Graphics g) {} //Affects menu behavior!
    public static void main(String[] args) {
    new P2();

    Well, my understanding of the way painting works is that a component doesn't UNPAINT itself. Instead a message is sent to the component under the coordinates of the menu to REPAINT itself.
    In your demo program the JFrame is the component under the JMenu. The paintComponent() method of JFrame is empty, so nothing gets repainted.
    I added super.paintComponent(g); to the method and everything works fine.

Maybe you are looking for

  • Using XML_Query in JAVA

    I'm using the OracleXMLQuery class to retrieve a CLOB from an Oracle table that was populated from an APEX Rich Text Field page. The XML file that is generated is fine except that the CLOB column has the angle brackets for the STRONG tag translated i

  • N86 games - Why only 2 buttons are avail and not a...

    hi, The top part of the phone which is covered by the slider has 4 buttons (for pic viewing, music and games). I found it very convenient to play games with it. However, only the 2 middle buttons are available for n gage games. The top and bottom one

  • Loading multisamples into Exs24 logic 8

    When loading multi samples using "automap using root key" into logic 8 it seems to stretch the regions all the way across and not to the desired note and put in equal positions Have I set it by mistake to do something a bit wierd? Thanks Nass

  • PO PDF PRINT

    Dear All            i am using PO Print(Output type NEU) using preprint paper.but now i need plain paper i devlop new program and form this mehod using pdf formet only how to creat new output type Thanks and regards Suresh

  • Macbook crashes when on battery power

    Laterly my macbook, which is uses very often, suddenly crashes every now and then when it's on battery power. Even when it's is (almost) full. It's 18 month's old. With the ac lead in everything is fine. Could there be something wrong with the batter