Captain's Universe Home
Captain's Universe Home
Cosmic Ray Muon DetectorTeleGarden Pages
Time on MarsBryophyllum Plants
Jupiter Radio AstronomyAncient Pages
Salzburg Tourist GuideEarth Magnetometer
  H O M E     AJAX & MORE     LINUX & MORE     RTAI     XENOMAI     ADEOS IPIPE      
    JAVA & BROWSERS     *NIX     ELECTRONICS     REVIEWS     ARTEMIA     FAIRY SHRIMP      



Java Application Template GUI Tutorial Part 4/5 - How to make an executable JAR file

In PART 3 I showed how to create the JFrame window and how to add the application (App1) to the contentpane. In this part of the tutorial we see the rest of the program, which will be displayed below the menubar and toolbar we have created in PART 3.

App1 contains the code for creating additional layout components, such as comboboxes, for drawing directly onto the JPanel and for handling the menubar event, such as opening and saving files.



App1.java:
// JAVA Application Template (C) 2005 www.captain.at
// class App1: The class for displaying the "content" of the application
// This is the class to add all application related code
// Also contains all functions for the menu- and toolbar

import javax.swing.*;
import java.awt.*;
import java.io.*;

public class App1 extends JPanel {
	public App1() {
		setLayout(new BorderLayout());
		JPanel p = new JPanel();
		GridLayout gly = new GridLayout(2,2,0,0);
		p.setLayout(gly);
		p.add(new JLabel("content"));
		p.add(new JLabel("area"));
		
		String[] items1 = new String[2];
		items1[0] = "first";
		items1[1] = "second";
		JComboBox combo1 = new JComboBox(items1);
		p.add(combo1);
		
		String[] items2 = new String[2];
		items2[0] = "first";
		items2[1] = "second";
		JComboBox combo2 = new JComboBox(items2);
		p.add(combo2);
		
		add("North",p);
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.black);
		g.drawLine(50, 50, 100, 100);
	}
	
	public void loadFile() {
		JFileChooser chooser = new JFileChooser(  );
		int result = chooser.showOpenDialog(this);
		if (result == JFileChooser.CANCEL_OPTION) return;
		try {
			File file = chooser.getSelectedFile(  );

		} catch (Exception e) { }
	}
	
	public void saveFile(  ) {
		JFileChooser chooser = new JFileChooser(  );
		int result = chooser.showSaveDialog(this);
		if (result == JFileChooser.CANCEL_OPTION) return;
		try {
			File file = chooser.getSelectedFile(  );
			System.out.println( file.toString(  ) );
		} catch (Exception e) { }
	}
	
}




PART 1 PART 2 PART 3 PART 4 PART 5


Last-Modified: Sat, 04 Feb 2006 16:03:10 GMT

Google
 
Web www.captain.at
go to top
© 1996-2010 . All rights reserved.
No reproduction, distribution, publishing or transmission of the copyrighted materials at this site is permitted. Policy
go to top