import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class densityProgram
{
public static void densityWindow ()
{
try
{
UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ());
}
catch (Exception e)
{
}
//Creates the frame, and sets close operation
JFrame w = new JFrame ("Density Calculator");
w.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//Creates a label which will mask the new frame
JLabel l = new JLabel ();
l.setPreferredSize (new Dimension (300, 300));
l.setOpaque (true);
l.setBackground (Color.black);
//Creates Buttons
JButton dB = new JButton ("Calculate Density");
JButton mB = new JButton ("Calculate Mass");
JButton vB = new JButton ("Calculate Volume");
JButton signin = new JButton ("Sign In");
//Creates numerous labels for the text fields
JLabel s = new JLabel (" ");
JLabel s1 = new JLabel (" ");
JLabel s2 = new JLabel (" ");
JLabel s3 = new JLabel (" ");
JLabel s4 = new JLabel (" ");
JLabel s5 = new JLabel (" ");
JLabel s6 = new JLabel (" ");
JLabel s7 = new JLabel (" ");
JLabel s8 = new JLabel (" ");
JLabel s9 = new JLabel (" ");
JLabel s10 = new JLabel (" ");
JLabel s11 = new JLabel (" ");
JLabel s12 = new JLabel (" ");
JLabel d1 = new JLabel ("Insert Mass");
JLabel d2 = new JLabel ("Insert Volume");
JLabel d3 = new JLabel ("Density : ");
JLabel v1 = new JLabel ("Insert Density");
JLabel v2 = new JLabel ("Insert Mass");
JLabel v3 = new JLabel ("Volume :");
JLabel m1 = new JLabel ("Insert Volume");
JLabel m2 = new JLabel ("Insert Density");
JLabel m3 = new JLabel ("Mass :");
JLabel p1 = new JLabel ("Insert Password");
JLabel u1 = new JLabel ("Insert Name");
//Creates numerous text fields
JTextField dtxt1 = new JTextField ("0", 10);
JTextField dtxt2 = new JTextField ("0", 10);
JTextField dtxt3 = new JTextField ("0", 10);
JTextField mtxt1 = new JTextField ("0", 10);
JTextField mtxt2 = new JTextField ("0", 10);
JTextField mtxt3 = new JTextField ("0", 10);
JTextField vtxt1 = new JTextField ("0", 10);
JTextField vtxt2 = new JTextField ("0", 10);
JTextField vtxt3 = new JTextField ("0", 10);
JTextField ptxt1 = new JTextField ("0", 10);
JTextField utxt1 = new JTextField ("0", 10);
//Creates a tabbed pane with panels
JTabbedPane tab = new JTabbedPane ();
JPanel d = new JPanel ();
JPanel m = new JPanel ();
JPanel v = new JPanel ();
//The Density Panel
d.setLayout (new BoxLayout (d, BoxLayout.Y_AXIS));
d.add (d1);
d.add (dtxt1);
d.add (s);
d.add (d2);
d.add (dtxt2);
d.add (s1);
d.add (dB);
d.add (s2);
d.add (d3);
d.add (dtxt3);
//The Mass Panel
m.add (m1);
m.add (mtxt1);
m.add (m2);
m.add (mtxt2);
//The Volume Panel
v.add (v1);
v.add (vtxt1);
v.add (v2);
v.add (vtxt2);
//The tabbed pane
tab.add (d, "Density");
tab.add (m, "Mass");
tab.add (v, "Volume");
//Adds components to frame
w.getContentPane ().add (l, BorderLayout.CENTER);
w.getContentPane ().add (tab, BorderLayout.CENTER);
//
w.pack ();
w.setVisible (true);
w.setResizable (false);
w.setSize (300, 300);
}
public static void main (String[] args)
{
javax.swing.SwingUtilities.invokeLater (new Runnable ()
{
public void run ()
{
densityWindow ();
}
}
);
}
}
|