modified RetirementCalculator class to work as an applet or a stand-alone java application
git-svn-id: svn://anubis/gvsu@430 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
a6e8d33cb0
commit
76ea152c71
@ -1,6 +1,12 @@
|
||||
|
||||
MAINCLASS := RetirementCalculator
|
||||
|
||||
all:
|
||||
javac RetirementCalculator.java
|
||||
javac $(MAINCLASS).java
|
||||
|
||||
.PHONY: run
|
||||
run:
|
||||
java $(MAINCLASS)
|
||||
|
||||
clean:
|
||||
-rm -f *.class
|
||||
|
@ -1,15 +1,47 @@
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* The main work of the application is done in this JPanel-extending class.
|
||||
* This allows the java class to be run as a stand-alone application or
|
||||
* as an applet within a web browser.
|
||||
*/
|
||||
class RetirementCalculatorPanel extends JPanel implements ActionListener
|
||||
{
|
||||
private JButton b;
|
||||
|
||||
public RetirementCalculatorPanel()
|
||||
{
|
||||
setLayout(new BorderLayout());
|
||||
b = new JButton("Hi There");
|
||||
b.addActionListener(this);
|
||||
add("South", b);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
b.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The "main" class of this file allows the app to be run as an applet
|
||||
* but also provides a "main" method to run as an application.
|
||||
*/
|
||||
public class RetirementCalculator extends JApplet
|
||||
{
|
||||
final static private String PROG_NAME = "Josh's Retirement Calculator";
|
||||
|
||||
RetirementCalculatorPanel panel;
|
||||
|
||||
public void init()
|
||||
{
|
||||
setLayout(new BorderLayout());
|
||||
JButton b = new JButton("Hi");
|
||||
add("South", b);
|
||||
panel = new RetirementCalculatorPanel();
|
||||
add(panel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
@ -23,4 +55,22 @@ public class RetirementCalculator extends JApplet
|
||||
public void stop()
|
||||
{
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
JFrame frame = new JFrame(PROG_NAME);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
RetirementCalculatorPanel panel =
|
||||
new RetirementCalculatorPanel();
|
||||
frame.getContentPane().add(panel);
|
||||
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user