Any Java experts,please help this Newbie.

Hey,any one of you knows how do you call a program from a button?
For example,I created a chat program and peer to peer share Program,and I want to join them together.
By clicking on a button on the peer to peer share program,the chat program would open in a new window.
Please Help Me!
Thanks alot.

Hi here is the complete example for you how you can call the other java classes in your main java class. Hope it will give you the idea. If still you have problems do write to me at [email protected]
* SixFrame.java
* Created on July 15, 2003, 10:26 AM
* @author sandeep
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class SixFrame extends JFrame implements ActionListener{
JButton btn[] = new JButton[6]; // this no will vary as per you requirements
/** Creates a new instance of SixFrame */
public SixFrame() {
JPanel pan = new JPanel();
for(int i=0;i<btn.length;i++){
btn[i] = new JButton((i+1)+"");
btn.addActionListener(this);
pan.add(btn[i]);
getContentPane().add(pan,BorderLayout.CENTER);
setSize(300,300);
setVisible(true);
/** Invoked when an action occurs.
public void actionPerformed(ActionEvent e) {
String comm = e.getActionCommand();
if(comm.equals("1")){
new FrameOne("One");
}else if(comm.equals("2")){
new FrameTwo("Two");
}else if(comm.equals("3")){
new FrameThree("Three");
}else if(comm.equals("4")){
new FrameFour("Four");
}else if(comm.equals("5")){
new FrameFive("Five");
}else if(comm.equals("6")){
new FrameSix("Six");
public static void main(String args[]){
new SixFrame();
class FrameOne extends JFrame{
FrameOne(String str){
super(str);
setSize(200,200);
setVisible(true);
class FrameTwo extends JFrame{
FrameTwo(String str){
super(str);
setSize(200,200);
setVisible(true);
class FrameThree extends JFrame{
FrameThree(String str){
super(str);
setSize(200,200);
setVisible(true);
class FrameFour extends JFrame{
FrameFour(String str){
super(str);
setSize(200,200);
setVisible(true);
class FrameFive extends JFrame{
FrameFive(String str){
super(str);
setSize(200,200);
setVisible(true);
class FrameSix extends JFrame{
FrameSix(String str){
super(str);
setSize(200,200);
setVisible(true);

Similar Messages

  • Java Experts please help - SimpleDateFormat.format reduces date by a day !!

    Hi,
    I am facing a very weird problem with SimpleDateFormat class. The input Date to SimpleDateFormat.format method is getting reduced by ONE DAY. This problem is happening at random and is not reproducible at will. Any help/pointers to resolve this issue is very much appreciated !!.
    Code is similar to the following code lines
    input = "2003-11-01 00:00:00.000000000";
    output = 31-Oct-2003 (strange !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.text.DateFormatSymbols;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Hashtable;
    import java.util.Locale;
    import java.util.TimeZone;
    import java.util.SimpleTimeZone;
    public class DateTester {
    /** Default constructor for Util.
    public DateTester() {
    private static String replace(String pattern, String from, String to) {
    return replace(pattern, from, to, null);
    private static String replace(String pattern, String from, String to, String notFrom) {
    StringBuffer sb = new StringBuffer();
    boolean finished = false;
    int index = pattern.indexOf(from);
    if (index < 0) return pattern;
    do {
    if (notFrom == null ||
    notFrom.length() + index > pattern.length() ||
    !pattern.substring(index, index + notFrom.length()).equals(notFrom)) {
    sb.append(pattern.substring(0, index));
    sb.append(to);
    sb.append(pattern.substring(index + from.length()));
    finished = true;
    } else index = pattern.indexOf(from, index + from.length());
    while (!finished && index >= 0);
    if (!finished) return pattern;
    return sb.toString();
    public static void main(String[] argv) {
              String pattern = "DD-MON-YYYY";
    System.out.println("original pattern =" + pattern);
    pattern = replace(pattern, "FM", "");
    pattern = replace(pattern, "AD", "G");
    pattern = replace(pattern, "A.D.", "G");
    pattern = replace(pattern, "BC", "G");
    pattern = replace(pattern, "B.C.", "G");
    pattern = replace(pattern, "AM", "a");
    pattern = replace(pattern, "A.M.", "a");
    pattern = replace(pattern, "PM", "a");
    pattern = replace(pattern, "P.M.", "a");
    pattern = pattern.replace('\"', '\t');
    pattern = pattern.replace('\'', '\"');
    pattern = pattern.replace('\t', '\'');
    pattern = replace(pattern, "DDD", "DDD");
    pattern = replace(pattern, "DAY", "dd");
    pattern = replace(pattern, "DD", "dd", "DDD");
    pattern = replace(pattern, "HH24", "HH");
    pattern = replace(pattern, "HH12", "KK");
    pattern = replace(pattern, "IW", "ww");
    pattern = replace(pattern, "MI", "mm");
    pattern = replace(pattern, "MM", "MM", "MMM");
    pattern = replace(pattern, "MONTH", "MMMMM");
    pattern = replace(pattern, "MON", "MMM");
    pattern = replace(pattern, "SS", "ss");
    pattern = replace(pattern, "WW", "ww");
    pattern = replace(pattern, "W", "W");
    pattern = replace(pattern, "YYYY", "yyyy");
    pattern = replace(pattern, "YYY", "yyy");
    pattern = replace(pattern, "YY", "yy");
    pattern = replace(pattern, "Y", "y");
    pattern = replace(pattern, "RRRR", "yyyy");
    pattern = replace(pattern, "RRR", "yyy");
    pattern = replace(pattern, "RR", "yy");
    pattern = replace(pattern, "R", "y");
    System.out.println("converted pattern =" + pattern);
    String origDate = "2003-11-01 00:00:00.000000000";
    System.out.println("original date =" + origDate);
    Timestamp origTimeStamp = Timestamp.valueOf(origDate);
    SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.getDefault());
    sdf.setLenient(false);
    String formattedDate = sdf.format((Date) origTimeStamp);
    System.out.println("formatted date =" + formattedDate);
    Thanks a lot for your time !

    Your code is too hard to read for me to look at it in great detail. When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read.
    However, I'm guessing it's a TimeZone issue. The midnight on 11/1 that you're setting is probably getting converted to GMT somewhere before the Date object is created. If you're in the U.S., then that's afternoon or evening on 10/31.
    Try:
    * Starting with a time that's later in the day on 11/1.
    * Formatting your date to include time and timezone when you print it. (Just for testing--you can put it back once you understand what's going on
    * Reading the Calendar, Timzone, Date, etc. APIs closely.
    * Reading any tutorials or texts you can find on the subject.
    * Writing a bunch of very small and simple tests to get an understanding of how this all fits together.
    Date/Time/TZ handling in Java is kinda tricky.

  • Any java experts pls help me in converting attribute to XML formats

    Pls help me oh my god i am a newbie here and i am given this project.
    I had just written a XML doc. which looks like this
    <ConsumerTransfer>
    <TransactionId>
    123:123
    </TransactionId>
    <Billingoption>
    cash
    </Billingoption>
    </ConsumerTransfer>
    I need to make this to attributes like
    private String TransactionId()
    private String BillingOption()
    and so on.....
    I need to convert this attributes to XML format
    can any show me an example or the source codes for this
    Really, I appreciate it.
    JimmyKnot

    For such node level operations I think that DOM would be a good idea. So here you go. Look for some nice tutorial for DOM and you got it.
    salut

  • I am totally confused!  Please help this newbie :-)

    Hi there,
    I am sorta new to Java. I've learned the basics of the language, but now I am finding myself totally confused with all the new stuff. There is SOOOOO much stuff on the java.sun.com website that I don't know where to begin.
    Ok, here is my question. Well, questions.
    1. Is there a document that describes when exactly one would want to use the J2EE as opposed to the J2SE?
    2. I want to develop a multi-platform small business desktop application. This application needs to support multiple users accessing a database on a server. It also needs to be capable of accessing a web service via the Internet. And there will be a web-based version of the application. So given these requirements, how do I know if I need the J2EE or not? I would like to avoid requiring the J2EE. The idea being to have a desktop application that can be sold for around $100 per seat license. J2EE application servers are relatively expensive, are they not?
    Where do I even begin? Can someone point me to a document or some information?
    Incidentally, I want to do all my development on Linux.
    Thanks for any help!
    Joe

    Suppose somebody said to you "I have just started to learn to cook, and I would like to open a restaurant in Paris. What should I serve, and will I need to know French?" What advice would you give that person? Well, hopefully you would tell that person to get a job washing dishes or waiting tables at a local restaurant and learn the business starting from the ground up.
    Same answer in your case. Start with J2SE and work on learning Java. Also learn about Internet technologies. Then probably after several months to a year you will start to understand the business, and the answers to your questions will become clearer.

  • Please help this newbie make a start with LabView 7

    Sorry for these very very basics but I failed to resolve these myself though I did my best.
    I try to make a GPIB i/o on a block diagram.How to ?
    I cannot find such in the functions menu.
    I find only a vi for typing direct commands ( which does work ).
    I tried many many variances, but end of all i get stuck, e.g. at : file>new>instrument i/o(gpib)>read and display>right click>controls>search>i/o....i get stuck.
    I am afraid I do miss a lot.....
    I have a NI GPIB PCI 488.2 card and some HPIB instuments.
    The PCI card and the NI 488.2 drivers work.
    I can read the instruments' dev.#.
    How should I implement instruments' r/w commands in an i/o block diagram ( if possible at all ).
    I cannot use VISA ( I
    assume C++ or VB is needed for that, which is beyond my capabilities ).
    Any help will be gratefully welcomed.
    Peter van Daalen.

    LabVIEW can do VISA and NI-488.2 directly; you don't need C++ or VB.
    First of all, you should see if there are instrument drivers available for your instruments. There are thousands of free drivers available on http://ni.com/idnet/. Search there first, because if you can find a driver for any of your instruments, it will save you a lot of time.
    If you can't find a driver, you will have to send and receive messages from the instrument directly, and this is where NI-VISA and NI-488.2 come in. The simplest way to get started with this direct communcation is to use the "Instrument I/O Assistant". This is in your "Functions->Input" palette, and you can read about it in the online help.
    The Instrument I/O Assistant will bring up a dialog to select th
    e device, send it a command and parse the results. Once you click "OK", it creates an Express VI on your diagram for you to incorporate into the rest of your application.
    I hope this helps you get started.
    Brian

  • Please help this newbie - Link to a Tabbed widget

    I have 4 Categories/links on the main splash page which I need to link to a widget on a separate page.  I need each link to go to the appropriate tab on the widget.  Is this something that is possible?  I have used the anchor/place gun on each tab and I have linked to them.  But when I preview, it each link goes to the same tab.  What am I missing?

    Thanks for the suggestion.  I had considered that and wondered if that would work, however, we were trying to avoid having to have the extra pages.  Hopefully in the next update we will get this ability.

  • Please help this Newbie.

    I have an iMac which I just picked up used. My problem is that I just installed an HP 1600 all in one. I downloaded the OS X drivers for it and everything went well. However the computer has an older version of Mac: Word & Excel (2001) and when I use these programs it goes into what I think is called classic mode. Then when I go to print, the printer I just installed is not present. In fact, when I go to the chooser there is a list of printers that I have no idea where they came from. How can I print to this newly installed printer from these programs and how do I delete these other printers which I don't have.
    Ps. When I go to the Print Center the only printer present is the newly installed HP. Also when I click on the configure button it does nothing. Did I do something wrong during the install?
    iMac   Mac OS X (10.2.x)  

    Hi, alpinecow -
    If that printer is usable in OS 9, you will probably need to install software for it into OS 9. Check the CD that came with the printer to see if there is an OS 9 (or Classic) set of software for it.
    I'm not familiar with that specific model HP printer, but may HP printers, particularly laser ones, are comfortable using OS 9's LaserWriter 8 driver. In Chooser, try clicking on LaserWriter 8 in the left pane; if the printer then shows up in the right pane, click it, then the Create or Setup button that becomes active at the bottom of that pane.
    There are some things that work differently in Classic vs. how they work in OS 9. If that printer needs AppleTalk, you may need to enable AppleTalk in Chooser. Not sure how that works in Classic, since OSX is running the hardware.
    As far as getting rid of other printers, go into the OS 9 (Classic) System Folder (not the folder named System, that's OSX), here - System Folder >> Printing Prefs >> Parsed PPD Folder, and from that folder discard the items for printers that no longer exist for that machine.

  • Can any Java expert help me? Urgent.

    I create a table---CourseDB in adatabase to store the Student ID ( student identification number) and the grades of the courses that they took.
    The structure of the table---CourseDB is:
    StudentID
    GradeofCourse1
    GradeofCourse2
    GradeofCourse3
    GradeofCourseN
    Here GradeofCourse1 means the grade of course 1, that the student obtained. GradeofCourse2, GradeofCourse3, GradeofCourseN have the same meaning.
    I want to use the following query to count the students
    who get g1 in course 1, and g2 in course 2, ......and gn in
    course n.
    Select COUNT(*)
    From CourseDB
    Where GradeofCourse1=g1 AND GradeofCourse2= g2
    ......AND GradeofCourseN=gn
    Here g1, g2,......,gn are grade, the values are: A,B,C,D.
    I want to consider all the possible combination of g1,g2,...,gn.
    The students take all the n courses:Course 1, Course 2,...., Course n, and may get A,B,C, or D in the n courses.
    For example:
    g1=A,g2=B,g3=C,.....,gn=D
    ( This means that the student gets A in Course 1, gets B in Course 2, gets C in Course 3,....., gets D in Course n. Many students may have the same situation. I want to know how many are the students?)
    Or:
    g1=B,g2=C,g3=D,......,gn=A
    To make the problem clear, I give a detail example:
    For example, there are two courses: course 1, course 2.
    I want to know how many stuent get "A" in course 1 and
    get "B" in course 2 at the same time.
    And I want to know all the grade combination of the two courses:
    course 1 course 2
    A A
    A B
    A C
    A D
    B A
    B B
    B C
    B D
    C A
    C B
    C C
    C D
    D A
    D B
    D C
    D D
    So that's 16 total combinations(4^2).
    My question is in the code how I can assign the values(A,B,C,D)
    to g1,g2,g3,.....,gn conveniently.
    The following "nested for loop" can solve the problem ( for example, there are 6 courses):
    for (char class1 = 'A'; class1 <= 'D'; class1++)
    for (char class2 = 'A'; class1 <= 'D'; class2++)
    for (char class3 = 'A'; class1 <= 'D'; class3++)
    for (char class4 = 'A'; class1 <= 'D'; class4++)
    for (char class5 = 'A'; class1 <= 'D'; class5++)
    for (char class6 = 'A'; class1 <= 'D'; class6++)
    select count(*)
    from CourseDB
    where GradeofCourse1=class1 AND GradeofCourse2 = class2 AND GradeofCourse3 = class3
    ....AND GradeofCourse6=class6
    But the problem is that in the "Where GradeofCourse1=class1 AND
    GradeofCourse2= class2 ......AND GradeofCourse6=class6" of the
    Query, the number of courses is not fixed, maybe six, maybe three,
    maybe four, so the depth of "nested for loop" can not be fixed.
    Can any Java expert give me some suggestions?
    Thanks in advance.
    Jack

    Jack,
    When you posted this on the other forum, it was quite a different question, but it has mutated to this point now. I believe what you want to do can be done with what MS Access calls a crosstab query and you can completely leave Java and any other programming language out of it. If you need to know how to do a crosstab query please take it to another forum.

  • "This message cannot be sent at this time."  I have been getting this pop-up for 3 days when trying to send out mail.  I don't know what to do!  I cannot send mail from this account on any ISP. Please help!

    "This message cannot be sent at this time."  I have been getting this pop-up for 3 days when trying to send out mail.  I don't know what to do!  I cannot send mail from this account on any ISP. Please help!

    lots of people seem to be havgin a problem sending email from iCloud webmail.
    does your email address have uppercase characters in it?
    if so, try creating an alias in lowercase (go to preferences in iCloud webmail and select 'accounts') and see if email sends okay from that

  • I can't forcequit firefox and shutdown my computer, nor can I open up any other programs or applications. Does anyone know how to fix this? please help this poor soul.

    I can't forcequit firefox and shutdown my computer, nor can I open up any other programs or applications. Does anyone know how to fix this? please help this poor soul.

    You can force quit applications
    >Force quit
    if that does not work you can force quit a computer shut down by hold the power button for an extended period.

  • My ipod 7th generation is not recognised by itunes and my computer. I am not able to transfer any songs. Please help me on this regard. I tried all the steps from apple website

    my ipod 7th generation is not recognised by itunes and my computer. I am not able to transfer any songs. Please help me on this regard. I tried all the steps from apple website

    This article should give you the options
    https://discussions.apple.com/docs/DOC-3991

  • My photoshop element 10 stop working,  I am not able to open ti anymore.  ?  I posted this question a few days ago and I did not get any anwer yer,  please help

    My photoshop element 10 stop working,  I am not able to open ti anymore.  ?  I posted this question a few days ago and I did not get any anwer yer,  please help

    I have photoshop premiere element 10  editor and organizer    and I have a Macbook pro 10,9,9
    When I try to open a picture with element editor or if I try to open PS editor directly  I see this
    file:///Users/main/Desktop/Screen%20Shot%202014-11-26%20at%201.17.35%20PM.png
    when I click on   Modify    it doesn't open and I have this window
    file:///Users/main/Desktop/Screen%20Shot%202014-11-26%20at%201.21.07%20PM.png
    and if I click  REOPEN  , I still have the same message
    Lucie

  • I bought an iphone 5 from one of my friends and unluckily I had yet lost his contact, I had update this iphone to IOs 7 and now it's be locked at iCloud because there was no password . Actually I dont know what I must do for its. Experts, please help me!

    I bought an iphone 5 from one of my friends and unluckily I had yet lost his contact, I had update this iphone to IOs 7 and now it's be locked at iCloud because there was no password . Actually I dont know what I must do for its. Experts, please help me!

    The friend who sold it to you needed to clear his Apple ID off the phone before he sold it to you. Of course if it wasn't his phone in the first place then he could not do so. He is your friend but you don't know where he is?
    There is nothing that will help you short of getting the password for the Apple ID from your friend. If you cannot obtain that there is no workaround.

  • My ipad is jammed.... the screen is about icloud back up. "this ipad hasn't been back up for two weeks.bla2... but the problem is my screen is locked . i couldnt do any thing ! please help me .....

    my ipad is jammed.... the screen is about icloud back up. "this ipad hasn't been back up for two weeks.bla2... but the problem is my screen is locked . i couldnt do any thing ! please help me .....

    if you can not unlock your ipad, you need to plug it into itunes and do a restore.
    If it will not ben able to restore you need to put it in dfu mode (holding down power and home for 10 seconds untill the screen goes completly blank) and then itunes will say it is in 'recovery'. Try that

  • Displaying Picture in a Java APPLICATION please help!!

    I have been trying to write a method that Displays a .jpg file when called. However I have not gotten far, every book I have tell you how to display pictures in an applet but not an application. I did find some code that is supposed to be for an application, but It does not compile right. Any help would be apprecidated!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PictureIt{
    public void makeImage() {
    //***Image Output Stream
    String imgFile
    = "d:\\temp\\TestImage.jpeg";
    out = new FileOutputStream(imgFile);
    BufferedImage image = null;
    image = (BufferedImage)createImage
    (panelJpeg.size.width, panelJpeg.size.height);
    Graphics g = image.getGraphics();
    panelJpeg.paintAll(g);
    }

    Displaying Picture in a Java APPLICATION please help!!
    Hope this helps.There is going to be two classes compile seperatly first class is what does the drawing
    here it is
    import javax.swing.*;
    import java.awt.*;
    public class draww extends JPanel {
    Image ball;
    int width1 = 100;
    int height1 = 100;
    public draww() {
    super();
    Toolkit kit = Toolkit.getDefaultToolkit();
    ball = kit.getImage("pic1.gif");
    public void paintComponent(Graphics comp) {
    Graphics2D comp2D = (Graphics2D) comp;
    comp2D.drawImage(ball, 20, 20, width1, height1, this);
    sound class is the container JFrame here it is
    import javax.swing.*;
    import java.awt.*;
    public class drawing extends JFrame {
    public drawing() {
    super("draw");
    setSize(400,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = getContentPane();
    draww d = new draww();
    pane.add(d);
    setContentPane(pane);
    setVisible(true);
    public static void main(String[] args) {
    drawing drawing1 = new drawing();
    PS Hope this helps and see you around

Maybe you are looking for

  • Is it possible to use your iPod Touch 4th Gen from your computer?

    I have an iPod Touch 4th Gen. And I broke the screen, the sent it in to get fixed... the people put the screen on wrong. It worked for a while, then it stopped working. I was trying to use it one day, and I accedentaly put on the curtain mode. So now

  • Error while connecting 10g developer to 11 g database (windows7 64 bit)

    pls help me.I have 11g database in my laptop and I installed oracle developer suit 10g ..everything seems normal but when I try to connect to database , I am getting tns error ora12154:TNS couldnt resolve the connect identifier.. I know this thing ab

  • Issue with payment run

    hi guru's We have one vendor in two company code one is India and one is USA. The bank account number  is different in vendor master data but both accounts in the same country. When we make the payment run it has to split to different account based o

  • XML content

    Hi I write web sites for a part time living ( very minimal stuff). Because Dreamweaver is expensive and unwieldy (in my mind) I use MS Expression Web 1 (and 2) . I have a xml based database of national members of the organisation I work for - the xml

  • Install of Reader X with MSI

    It appears that the file decompression location for Reader X has changed from Reader 9.  In 9 it was users>username>local settings>application data> adobe .  After trying to run install using the -nos_ne swtich we are uagle to find the .nsi file.  An