Buttons: I need a little help

Hello again,

I will be very thankful if someone help me to realize what i want ;

I have written a program and it uses GUI window to show output.

I have also written another program and it uses GUI,too.

What i want is to combine them in a single GUI window.

It will have 2 buttons ; button1 and button2 to change between

the outputs of two programs.

If you can combine those two in a single (two classes of course)

program,i can adapt it to my programs,

thank you so much ;

Program 1

import java.awt.Font;

import java.awt.Color;

import java.awt.Graphics;

import javax.swing.JPanel;

publicclass Sampleextends JPanel

{

publicvoid paintComponent( Graphics g )

{

g.setFont(new Font("Serif", Font.BOLD, 12 ) );

g.setColor(new Color(0,0,0) );

g.drawString("Output1", 50, 50 );

}}

Program 2

import java.awt.Font;

import java.awt.Color;

import java.awt.Graphics;

import javax.swing.JPanel;

publicclass Sampleextends JPanel

{

publicvoid paintComponent( Graphics g )

{

g.setFont(new Font("Serif", Font.BOLD, 12 ) );

g.setColor(new Color(0,0,0) );

g.drawString("Output2", 50, 50 );

}}

also both classes uses this class to execute;

import javax.swing.JFrame;

publicclass Fonts

{

publicstaticvoid main( String args[] )

{

JFrame frame =new JFrame("LandslideVisual by Berkay G鰇tan" );

frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

LandslideDetermination fontJPanel =new LandslideDetermination();

frame.add( fontJPanel );

frame.setSize( 500, 500 );

frame.setVisible(true );

}

}

[3278 byte] By [BG18a] at [2007-11-27 4:50:11]
# 1
Do you really need to subclass and override paintComponent just to show someoutput? Why not use a text component? So much simpler, really!
Hippolytea at 2007-7-12 10:03:27 > top of Java-index,Java Essentials,New To Java...
# 2

There is no need to extend JPanel for what you are asking for. There is a tutorial on the hierarchy of GUI components here: http://java.sun.com/docs/books/tutorial/uiswing/components/index.html

Here is the simplest demo GUI that I can give you:

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

public class SimpleGUI implements ActionListener {

JFrame frm;

JPanel pan;

JTextField txt;

JButton btn;

public SimpleGUI()

{

frm = new JFrame("Simple GUI");

frm.setSize(500,500);

frm.setDefaultCloseOperation(frm.EXIT_ON_CLOSE);

pan = new JPanel();

frm.getContentPane().add(pan);

JButton btn = new JButton("Click Me");

btn.addActionListener(this);

txt = new JTextField();

txt.setPreferredSize(new Dimension(100, 20));

pan.add(btn);

pan.add(txt);

frm.pack();

frm.setVisible(true);

}

public void actionPerformed(ActionEvent event) {

txt.setText("Button clicked");

}

public static void main(String[] args)

{

SimpleGUI test = new SimpleGUI();

}

}

--http://www.andybriggs.com

Psybera at 2007-7-12 10:03:27 > top of Java-index,Java Essentials,New To Java...
# 3
tutorial web page was beneficial ,that was what i was looking for.I learned how to do it, thank you both.
BG18a at 2007-7-12 10:03:27 > top of Java-index,Java Essentials,New To Java...