Hello World with 2 forms

I'm just starting out with Swing, and I'm having trouble creating a second form. Are there any good tutorials around for this? The perfect example would be a program with a button in the main form that when pressed would open a new form with another button to close it.

maybe this helps.
i'm sure there are better ways to do this.
this is just one way.
package test;
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
class Test extends JFrame implements ActionListener{
     JPanel yourPanel;
     JButton bttn;
     public Test() {
          init();
     public void init() {
          yourPanel = new JPanel(new BorderLayout());
          bttn = new JButton("Open");
          bttn.addActionListener(this);
          yourPanel.add(bttn, BorderLayout.CENTER);
          this.getContentPane().add(yourPanel);
          this.setSize(200,200);
          this.setVisible(true);
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     public void actionPerformed(ActionEvent e) {
          JButton closeBttn = new JButton("Close");
          if (e.getSource() == bttn){
               final JFrame newWin = new JFrame();
               JPanel newPanel = new JPanel(new BorderLayout());
               newPanel.add(closeBttn, BorderLayout.CENTER);
               newWin.getContentPane().add(newPanel);
               newWin.setSize(100,100);
               newWin.setVisible(true);
               closeBttn.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                              newWin.setVisible(false);
  public static void main(String args[]) {
          new Test();
}

Similar Messages

  • Anybody can suggest quick sample 'Hello World' with ADF/JSF to deploy on WC

    We are using JDeveloper 11g, and Web Center 10.1.3.2.
    We have Oracle Portals 10.1.2.0.2
    We want to develop a portlet and deploy it to WC 10.1.3.2 to use it in Portals 10.1.2.0.2.
    Could anybody suggest any working "Hello World' sample with ADF/JSF to deploy on WC 10.1.3.2 WSRP.
    TIA

    Just to clarify. Oracle Portal 10.12.0.2 did not support WSRP based portlets (this was introduced in 10.1.4 or Portal) as such you would need to develop a JPDK based portlet in order to use it in both Portal 10.1.2.0.2 and WebCenter. If you upgrade the portal to 10.1.4 you will be able to use a WSRP 1.0 based portlet in both products (WebCenter also supports the draft WSRP2.0 extensions so make sure that you register the correct WSDL file)
    If you are trying to use JSF components within the Portlet itself you will need to use the JSF Portlet Bridge which accounts for the differences in lifecycle between JSF and WSRP.

  • Problem with JNI hello world

    I found some tutorial on SUN site on how to use JNI. I'm using Eclipse to compije Java and C (via Cygwin) files. Here are complete files:
    Hello.java:
    class Hello
         public native void sayHello();
         static
              try
              System.loadLibrary("hello");
              catch(Exception e)
                   System.out.println("exc");
         public static void main(String[] args)
              Hello h = new Hello();
              h.sayHello ();
    }Hello.c:
    #include <mingw/_mingw.h> //because there are some types needed for JNI
    #include <jni.h>
    #include "Hello.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL Java_Hello_sayHello
      (JNIEnv *env, jobject obj)
         printf("Hello world!\n");
         return;
    }Makefile:
    hello.dll : Hello.o Hello.def
         gcc -g -shared -Wl,--kill-at -o hello.dll Hello.o hello.def
    Hello.o : Hello.c Hello.h
         gcc -c -g -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" Hello.c -o Hello.o
    Hello.h : Hello.class
         javah -jni Hello
    clean :
         rm Hello.h
         rm Hello.o
         rm hello.dllHello.def
    EXPORTS
    Java_Hello_sayHelloEverything goes well, but when I run java program it does nothin (it should print message, but it just exit without any error).I'm sure that it's something stupid, but I cant see what. Can anyone tell me what am I doing wrong?
    Thenks.

    Answer 1: yes, there was no problem. I compiled and started simple 'hello world' program from Cygwin and from WinXP console, and it worked well.
    Answer 2: This is weird, I changed code to this:
    Hello.java:
         public native int getInt();
              System.out.println("Returned int is " + h.getInt());Hello.c:
    JNIEXPORT jint JNICALL Java_Hello_getInt
      (JNIEnv *env, jobject obj)
         return 25;
    }It does not print anything. I started this program from Cygwin and from WinXP console, and from Eclipse. Only if I debug in Eclipse (step by step) I get:
    Returned int is 25and still I don't get Hello string printed (even if I go step by step). It looks like cygwin has some problem with OS. Do you have any idea what to do, I'm a bit confused?
    Thank you.
    Message was edited by:
    zly

  • ADF :Hello world Page and discussion for its deployment with Oracle guys!

    I have written a small article of creating hello world page in ADF with screenshtots,here is the link:
    http://mukx.blogspot.com/2008/03/adf-hello-world-page.html
    This article can help you for a self starter with ADF and some baisc idea of same components in both OAF and ADF.
    Here is the link of recent mail conversation with Oracle guys for ADF project deployment:
    http://mukx.blogspot.com/2008/04/discussion-for-deploying-adf-project-in.html
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi Mukul,
    Thanks for the tute, am new to ADF so this was of great help to me. I had a query, if i want to have my own look and feel web pages and Oracle ADF ones, does the custimzation involve too much of manual coding or can be done easily in ADF. Also is there an equivalent tag to div in ADF Faces

  • I have a bare minimum script with the following line (also had the line echo Hello World, but removed for simplicity).

    I have a bare minimum script with the following line (also had the line echo Hello World, but removed for simplicity).
    #!/bin/sh  <-- only line of code currently in the file
    when I try to run, I get the following error.  Likewise if the line is #!/bin/bash, but /bin/bash is then the bad interpreter.
    -bash: ./test.sh /bin/sh: bad interpreter: Operation not permitted
    I'm running from a terminal window.
    Any helpful hints for resolution?  Thank you in advance.

    I did some more searching and found the answer here: https://discussions.apple.com/thread/3733470?start=30&tstart=0
    I obtained TextWrangler and recreated the file.
    Thank you for your input.

  • Error with select fnd_web_sec.URLEncrypt('hello', 'world') from dual;

    Hi Team
    WE have a EBS 11.5.10.2 with DB 11.1.0,7 on HPUX 11.23.
    And we have a error;
    APP:
    FRM-40735: ON_ERROR trigger raised unhandled exception ORA-01001
    SQL> select fnd_web_sec.URLEncrypt('hello', 'world') from dual;
    select fnd_web_sec.URLEncrypt('hello', 'world') from dual
    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    Process ID: 10119
    Session ID: 978 Serial number: 7
    Regards,
    Guido

    Moderation:
    Stay with your original thread on this topic:
    https://forums.oracle.com/thread/2595095
    It is current and people have already tried to help you there.
    This new duplicate post is locked.

  • Problem with "Hello World"  program

    i am new to java.
    i have recently installed java and the version is :
    E:\>java -showversion
    java version "1.6.0_06"
    Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
    Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
    First.java_
    class First
    public static void main (String[] args)
    System.out.println("Hello World!");
    My "First.java" compiles fine.
    but,when i execute it, i got the following Error:
    E:\>javac First.java
    E:\>java First
    Exception in thread "main" java.lang.NoClassDefFoundError: First
    Caused by: java.lang.ClassNotFoundException: First
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    i need assistance..

    As stated in the [thread earlier today|http://forum.java.sun.com/thread.jspa?threadID=5304111&tstart=0], you need to specify the classpath like this:
    java -cp . First(Note that there is a period between the -cp and First with spaces separating the period from the -cp and the First).

  • Having trouble with Hello World web applet...

    I used this tutorial,
    http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter01/simpleApplet.html
    However, I STILL get a red X on my personal webpage even after compiling everything here.. Another weird thing was, I couldn't even compile it correctly without removing the 'public' before the 'class'.
    Heres my code
    class HelloWorld extends java.applet.Applet
       public void paint(java.awt.Graphics g)
            g.drawString("Hello World!",50,25);
            System.out.println("Hello World!");
    } HTML:
    <applet code="HelloWorld.class" width="150" height="50"></applet>And the error I get.
    load: HelloWorld.class is not public or has no public constructor.
    java.lang.IllegalAccessException: Class sun.applet.AppletPanel can not access a member of class HelloWorld with modifiers ""
         at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)Somebody help me please?

    Oh wait, the java file needed the same name as the class...
    Getting the same problem still:
    oad: HelloWorld.class is not public or has no public constructor.
    java.lang.IllegalAccessException: Class sun.applet.AppletPanel can not access a member of class HelloWorld with modifiers ""
         at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    public class HelloWorld extends java.applet.Applet
       public void paint(java.awt.Graphics g)
            g.drawString("Hello World!",50,25);
            System.out.println("Hello World!");
    null

  • Hello World and FSBL don't work with ZC702

    Hi everyone,
    I'm very confused about my issue. I've a ZC702 Board and use SDK 2014.4 and Vivado 2014.4 (both 64 bit) on a Windows 7 machine.
    I've created a simple design with Vivado. The only element I have is a Zynq processor. I turned on some controller ( like I2C, QSPI, CAN, SD) and, configured the CAN CLK prescaler (see Zynq-7000 AP SoC Technical Reference Manual v1.10, page 581) and that's it.
    After I exported the bitstream and launched the SDK, I created a FSBL project and a Hello World project. Nothing spectacular, nothing weird. Everything I used came out of the box.
    I used the Xilinx tools to create a boot image and flashed the memory.
    The boot sequence works fine till it has to execute the HelloWorld.elf. I get following message :
    Application
    Handoff Address: 0x00000000
    In FsblHookBeforeHandoff function
    No Execution Address JTAG handoff
    Here is the thing: If I use the ZC702 pre-defined hard platform, with I can choose in the creation process of a new project, everything works fine. But that's not, what I want and that's not, what I need.
    Why does this happen and how can I understand and reconstruct this behavior to configure and fix this kind of problems
    in future by myself?
    I'm looking forward to your suggestions
    P.S: I've done a lot of googling but I couldn't find anything suitable.

    Check this AR and attached design
    http://www.xilinx.com/support/answers/50869.html

  • Basic (and I mean basic) java problem with a simple hello world script

    I have a simple cut-and-paste html page and java class in my /home/jc158027/java directory.
    jc158027> cat HelloWorld.java
    import java.applet.*;
    import java.awt.*;
    public class HelloWorld extends Applet{
    Label helloLabel = new Label ("Hello World");
    public void init () {
      setBackground (Color.yellow);
      add (helloLabel);
    }Ok, so I javac HelloWorld.java and get HelloWorld.class, so far so good.
    Next I create my html page:
    jc158027> cat hw.html
    <HTML>
    <HEAD>
    <TITLE>Jay's Java Test Page</TITLE>
    <BODY>
    <HR>
    This line of text comes before the applet.<P>
    <APPLET CODE = 'HelloWorld.class" WIDTH=500 Height=90>
    </APPLET>
    <P>
    This line of text comes after the applet.
    </BODY>
    </HTML>The result is that the text lines work, I get a nice grey box with no applet running. Looking at my console I get the following error:
    Caused by: java.io.FileNotFoundException: /home/jc158027/java/HelloWorld/class".class (No such file or directory)
    What I don't understand is the HelloWorld/class".class portion, shouldn't it be just either HelloWorld".class or HelloWorld/class, it is as though it is trying to look in a directory (class) that does not exist.
    What am I missing here?

    And if you put dots in where it expects a class name, it assumes those dots are to separate levels in a package name.
    So it was looking for a class named "class", which would be in a file called class.class, in a package named "HelloWorld". Packages correspond to directories relative to some classpath root, so it looked for the directory HelloWorld to be the parent of the classes in the HelloWorld package.

  • Problem with a simple hello world JSP

    We have just installed WLS Express 7.0 (just downloaded) on a Solaris 8 server. Using the dmwiz.sh, we have created a new domain with a managed server. Both the Admin Server and managed server have started and are running. When I tried to load a sample web application (a war file that has a hello world JSP), I got a HTTP 500 internal server error in serving the hello.jsp page. This sample works fine in Windows WLS Express 7.0.
    Can someone please help? Thank you in advance.

    Alex <[email protected]> wrote:
    We have just installed WLS Express 7.0 (just downloaded) on a Solaris
    8 server. Using the dmwiz.sh, we have created a new domain with a managed
    server. Both the Admin Server and managed server have started and are
    running. When I tried to load a sample web application (a war file
    that has a hello world JSP), I got a HTTP 500 internal server error
    in serving the hello.jsp page. This sample works fine in Windows WLS
    Express 7.0.
    Can someone please help? Thank you in advance.Hi,
    It seems the installation of the server worked fine as you were able to start
    the servers.
    You may try posting this message to the weblogic.developer.interest.jsp newsgroup.
    If you are
    not using the latest service pack, please try using that.
    regards,
    Platform Team
    BEA Systems

  • Hello World runs with errors

    I am having trouble with the Hello World program in JDeveloper RUP7 setup.
    And I have searched these forums, but no threads describe this exact issue.
    When I run the Hello World, the first page appears fine, with all the links showing.
    However, when I click on any of the links in the page, then I get an error,
    and the page dumps me to our main Applications Login screen.
    The error I get (after clicking on a link) is:
    Unexpected URL parameters have been detected and will be ignored
    And the link I click on in Hello World application is:
    http://scottma09.corpusa.napole.local:8988/OA_HTML/OA.jsp?
    OAFunc=FWK_TOOLBOX_HELLO&
    OAPB=FWK_TOOLBOX_BRAND&
    OAHP=FWK_TOOLBOX_TUTORIAL_APP&
    OASF=FWK_TOOLBOX_HELLO&
    transactionid=1255486469&oas=kIYCU8z8RLu95eOyqIqWaw..
    Any advice is greatly appreciated.

    Thank you both for your input.
    I was already using my Oracle user acct, which had been setup properly.
    But when installing JDeveloper, I did not see any mention of:
    Tools -> Preferences -> Embedded OC4J -> Default Local IP Address (Recommended)
    Selecting that option solved my problem.
    Also, I had been investigating the advice in this other thread, but it did not help:
    Unexpected URL parameters have been dete

  • Getting ConnectException in linux with Hello World socket program

    Hello
    i'm running a hello world application that uses sockets ( [found here|http://blog.taragana.com/index.php/archive/understanding-java-simplified-hello-world-for-socket-programming/] ) . I'm running it using a windows machine and a linux machine. When the windows machine is the server, and linux the client, no problem, the application works fine. But when the server is linux and the client is in windows i got a
    java.net.ConnectException: Connection timed out: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:352)
    in the linux machine i've checked the port being used and it seems to be listening
    logan@logan-desktop:~$ netstat --listening |grep 6500
    tcp6 0 0 [::]:6500 [::]:* LISTEN
    i've also tried changing the port and i got the same error
    and i have to say that there is no firewall installed in the linux machine and in the windows machine i disabled the firewall but i'm still getting the same error
    what else should i check? or any clue about what could be happening?
    thank you in advance
    any help would be appreciated

    puki_el_pagano wrote:
    i'm running a hello world application that uses sockets ( [found here|http://blog.taragana.com/index.php/archive/understanding-java-simplified-hello-world-for-socket-programming/] ) . I'm running it using a windows machine and a linux machine. When the windows machine is the server, and linux the client, no problem, the application works fine. But when the server is linux and the client is in windows i got a
    java.net.ConnectException: Connection timed out: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:352)
    in the linux machine i've checked the port being used and it seems to be listening
    logan@logan-desktop:~$ netstat --listening |grep 6500
    tcp6 0 0 [::]:6500 [::]:* LISTEN
    i've also tried changing the port and i got the same error
    and i have to say that there is no firewall installed in the linux machine Are you absolutely sure?
    what else should i check? On the windows box
    open a cmd window
    C:> telnet linuxbox 6500

  • XSQL Hello World

    I am working with IE5 8i and Java Web Srvr 2.0
    I have done followings..
    1. set classpath for 4,5 jars
    2. added oracle servlet to JWS
    3. added servelet aliases
    4. configured xmlconfig for local database
    when i call http://hostname:9090/examples/test.xsql i get blank result back.
    test.xsql incluedes
    <xml>
    <xsql....connection=orcl
    select 'hello world' as 'testxml' from dual
    </xsql>
    any ideas?
    I am also looking for a specific example of inserting a xml output from html form into Oracle clob column.
    thanks
    syed

    You should check the log files for the servlet engine you are using to find out what is happening.
    Oracle XML Team
    null

  • 15 Seconds to Display "Hello World"?

    I've just installed Flex Developer 3 on OS X 10.5.7 (2.4 GHz and 4 GB RAM). When I run the "Hello World" application from "A Beginner's Guide" by Davis and Phillips, it takes about 15 seconds to display "Hello World".
    The result is the same when I'm using Firefox 3.5.1 or Safari 4.0.2.
    When I export the project and run the html filebin-debug, I get a delay of about 11 seconds.
    When I export the project and run the html file in bin-release, I get "Hello World" in about 1 second.
    I also noticed a similar delay when opening database driven applications. The browser reads "Loading", I get the PWOD, and then the form appears.O Once the page loads and Flash displays, the application loads data very quickly (amazingly quickly!)
    In contrast, when I FF 3.5.1 on XP SP3 under Fusion 2.0.5 and open the html files in debug and release, they load in 1 second.
    Is there a patch to apply or something I need to set to get rid of the long delay on OS X?
    Thanks in advance,
    Douglas von Roeder

    The solution was to right click on the application in the browser and stop it from connecting to a remote debugger.
    I've been working on a few different applications which were data-driven apps, some of which were running on a remote machine. Hence the need to connect to a debugger on the hosted box.
    Once I changed the debugger settings, the situation was solved.

Maybe you are looking for