Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java GUI for java applications 1

Status
Not open for further replies.

mooster2

Programmer
Jan 26, 2004
21
CA
I have four little java applications/classes and I want them to be presented all together.

I'm trying to make some sort of Main Java GUI that will display all of the four applications, one in each corner of the window, like in this picture:

fourapps.GIF


Can somebody tell me if this is feasible? if it is, can you hint me on how I can implement this? :)

Basically, the "Main application" simply holds the four little applications. It can also just execute them and place them in separate locations.

Any feedback is appreciated :) Thanks
 
//Try this code changed from sun example
// ifr.java
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;

import java.awt.event.*;
import java.awt.*;

public class ifr extends JFrame {
JDesktopPane desktop;
int taskNo=1;

public ifr() {
super("InternalFrameDemo");

//Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height-inset*2);

//Quit this app when the big window closes.
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

//Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
createFrame(1); //Create first window
setContentPane(desktop);
setJMenuBar(createMenuBar());

//Make dragging faster:
desktop.putClientProperty("JDesktopPane.dragMode", "outline");
}

protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();

JMenu menu = new JMenu("Document");
menu.setMnemonic(KeyEvent.VK_D);
JMenuItem menuItem = new JMenuItem("New");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
taskNo++;
createFrame(taskNo);
}
});
menu.add(menuItem);
menuBar.add(menu);

return menuBar;
}

protected void createFrame(int myChoice) {

if (myChoice==1)
{
task1 frame2 = new task1();
frame2.setVisible(true); //necessary as of kestrel
desktop.add(frame2);
try {
frame2.setSelected(true);
}
catch (java.beans.PropertyVetoException e) {}
}
else
{
task1 frame2 = new task1();
frame2.setVisible(true); //necessary as of kestrel
desktop.add(frame2);
try {
frame2.setSelected(true);
}
catch (java.beans.PropertyVetoException e) {}
}
}

public static void main(String[] args) {
ifr frame = new ifr();
frame.setVisible(true);
}
}
// task1.java
import javax.swing.JInternalFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.*;
import java.awt.*;

class task1 extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;
JTextField myJText;
JTextField myJText2;
JTextField myJText3;

public task1() {
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable

getContentPane().setLayout(new GridLayout(3,2));
myJText = new JTextField("25.0");
myJText2 = new JTextField("12.0");
myJText3 = new JTextField("0.0");

JLabel myJLab = new JLabel("+");
JLabel myJLab2 = new JLabel("=");
JButton processBtn = new JButton("process");
ActionListener myListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
myJText3.setText(String.valueOf( Double.parseDouble(myJText.getText())+Double.parseDouble(myJText2.getText()) ));
}

};
processBtn.addActionListener(myListener);

getContentPane().add(myJText);
getContentPane().add(myJLab);
getContentPane().add(myJText2);
getContentPane().add(myJLab2);
getContentPane().add(myJText3);
getContentPane().add(processBtn);
//...Create the GUI and put it in the window...

//...Then set the window size or call pack...
setSize(300,300);

//Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}
}

// write your code in task1, task2 , task3
 
Propser, I love you ^_^ you are a life saver.. i was stressed for several weeks and you just gave me the perfect solution =D

How can I even thank you enough? :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top