 |
|
 |
 |
  | import java.awt.event.*; import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.text.DecimalFormat;
public class Skateboard extends MouseInputAdapter implements ActionListener, SwingConstants { private JFrame window; private JComboBox cboTrucks = new JComboBox(); private JRadioButton [] radWheels = new JRadioButton[4]; private JCheckBox [] chkOther = new JCheckBox[4]; private JTextField txtSubTotal = new JTextField(); private JTextField txtTax = new JTextField(); private JTextField txtTotal = new JTextField(); private String [] decks = {"Master Thrasher - $60", "Dictator - $45", "Street King - $50"}; private JList lstDecks = new JList(decks); private JScrollPane scrlDecks = new JScrollPane(lstDecks); private ActionEvent actionEvent; private MouseEvent mouseEvent; public static void main(String [] args) { Skateboard c = new Skateboard(); } public Skateboard() { final int X = 200; final int Y = 200; final int WINDOW_WIDTH = 900; final int WINDOW_HEIGHT = 250; window = new JFrame("Skateboard Designer"); window.setBounds(X,Y,WINDOW_WIDTH,WINDOW_HEIGHT); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buildGUI(); window.setVisible(true); update(); }
public void buildGUI() { Color backColor = window.getBackground(); Font font = new Font("SansSerif",Font.BOLD+Font.ITALIC,25);
JPanel panDecks = new JPanel(); panDecks.setBackground(backColor); panDecks.setLayout(new GridLayout()); panDecks.setBorder(BorderFactory.createTitledBorder("Decks")); panDecks.add(scrlDecks); lstDecks.setSelectedIndex(0); lstDecks.addMouseListener(this); cboTrucks.setBorder(BorderFactory.createTitledBorder("Trucks")); cboTrucks.addItem("7.75-inch axle - $35"); cboTrucks.addItem("8-inch axle - $40"); cboTrucks.addItem("8.5-inch axle - $45"); cboTrucks.addActionListener(this);
JPanel panWheels = new JPanel(); panWheels.setLayout(new GridLayout(4,1)); panWheels.setBorder(BorderFactory.createTitledBorder("Wheels")); String [] radNames = {"51 mm - $20", "55 mm - $22", "58 mm - $24", "61 mm - $28"}; ButtonGroup group = new ButtonGroup(); for (int i = 0; i < radWheels.length; ++i) { radWheels[i] = new JRadioButton(radNames[i]); group.add(radWheels[i]); radWheels[i].addActionListener(this); panWheels.add(radWheels[i]); } radWheels[0].setSelected(true);
String [] chkNames = {"Grip tape - $10", "Bearings - $30", "Riser pads - $2", "Nuts & bolts kit - $3"}; JPanel panOther = new JPanel(); panOther.setBorder(BorderFactory.createTitledBorder("Other")); panOther.setLayout(new GridLayout(4,1)); for (int i = 0; i < chkOther.length; ++i) { chkOther[i] = new JCheckBox(chkNames[i]); chkOther[i].addActionListener(this); panOther.add(chkOther[i]); } JPanel panTop = new JPanel(); panTop.setLayout(new GridLayout(1,4,10,10)); panTop.add(panDecks); panTop.add(cboTrucks); panTop.add(panWheels); panTop.add(panOther); JPanel panLeftBottom = new JPanel(); panLeftBottom.setLayout(new GridLayout()); panLeftBottom.add(txtSubTotal); JPanel panMidBottom = new JPanel(); panMidBottom.add(txtTax); panMidBottom.setLayout(new GridLayout()); JPanel panRightBottom = new JPanel(); panRightBottom.add(txtTotal); panRightBottom.setLayout(new GridLayout()); JPanel panBottom = new JPanel(); panBottom.setLayout(new GridLayout(1,3,10,10)); panBottom.add(panLeftBottom); panBottom.add(panMidBottom); panBottom.add(panRightBottom); panLeftBottom.setBorder(BorderFactory.createTitledBorder("Subtotal")); txtSubTotal.setFont(font); txtSubTotal.setEditable(false); txtSubTotal.setHorizontalAlignment(RIGHT);
panMidBottom.setBorder(BorderFactory.createTitledBorder("Tax")); txtTax.setFont(font); txtTax.setEditable(false); txtTax.setHorizontalAlignment(RIGHT);
panRightBottom.setBorder(BorderFactory.createTitledBorder("Total")); txtTotal.setFont(font); txtTotal.setEditable(false); txtTotal.setHorizontalAlignment(RIGHT);
window.setLayout(new BorderLayout(10,10)); window.add(panTop,BorderLayout.CENTER); window.add(panBottom,BorderLayout.SOUTH); } public void mouseClicked(MouseEvent e) { mouseEvent = e; update(); } public void actionPerformed(ActionEvent e) { actionEvent = e; update(); } private void update() { String strDeck = (String)(lstDecks.getSelectedValue()); strDeck = strDeck.substring(strDeck.length()-2); String strTruck = (String)(cboTrucks.getSelectedItem()); strTruck = strTruck.substring(strTruck.length()-2); String strWheels = ""; for (int i = 0; i < radWheels.length; ++i) { if (radWheels[i].isSelected()) { strWheels = radWheels[i].getText(); int length = strWheels.length(); strWheels = strWheels.substring(length-2); } }
String [] strOther = new String[4]; int otherIndex = 0; for (int i = 0; i < chkOther.length; ++i) { if (chkOther[i].isSelected()) { strOther[otherIndex] = chkOther[i].getText(); int length = strOther[otherIndex].length(); strOther[otherIndex] = strOther[otherIndex].substring(length-2); if (strOther[otherIndex].charAt(0) == '$') { strOther[otherIndex] = strOther[otherIndex].substring(1); } ++otherIndex; } }
try { DecimalFormat df = new DecimalFormat("$#0.00"); final double TAX_RATE = 0.06; double deck = Double.parseDouble(strDeck); double truck = Double.parseDouble(strTruck); double wheels = Double.parseDouble(strWheels); double other = 0; for (int i = 0; i < otherIndex; ++i) { other += Double.parseDouble(strOther[i]); } double subtotal = 0; subtotal += deck + truck + wheels + other; txtSubTotal.setForeground(Color.blue); txtSubTotal.setText(df.format(subtotal)); double tax = TAX_RATE * subtotal; txtTax.setForeground(Color.blue); txtTax.setText(df.format(tax)); double total = subtotal + tax; txtTotal.setForeground(Color.blue); txtTotal.setText(df.format(total)); } catch (NumberFormatException e) { txtSubTotal.setForeground(Color.red); txtSubTotal.setText("---"); txtTax.setForeground(Color.red); txtTax.setText("---"); txtTotal.setForeground(Color.red); txtTotal.setText("---"); } } }
|
 |
 |
 |
 |
  | File chooser and image viewer program
|
 |
 |
 |
 |
  | import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*;
public class FileDialog extends JFrame { private JButton btnOpen; private JLabel lblImage = null; public static void main(String[] args) { FileDialog fd = new FileDialog(); } public FileDialog() { super("File Dialog"); // set window title final int X = 300; final int Y = 200; final int WINDOW_WIDTH = 700; // set window dimensions final int WINDOW_HEIGHT = 400; this.setBounds(X,Y,WINDOW_WIDTH,WINDOW_HEIGHT); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // set close operation buildGUI(); // add components to window this.setVisible(true); // make window visible } public void buildGUI() { btnOpen = new JButton("Open File"); this.setLayout(new BorderLayout()); this.add(btnOpen,BorderLayout.SOUTH); this.pack(); btnOpen.addActionListener(new ActionListener() { // what to do when button pressed public void actionPerformed(ActionEvent event) { try { if (lblImage != null) remove(lblImage); JFileChooser fileDialog = new JFileChooser(); int status = fileDialog.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { File selectedFile = fileDialog.getSelectedFile(); String filename = selectedFile.getPath(); lblImage = new JLabel(new ImageIcon(filename)); add(lblImage,BorderLayout.CENTER); pack(); // resize window to fit picture } } catch (Exception e) { JOptionPane.showMessageDialog(null,e.getMessage()); } } }); } }
|
 |
 |
 |
 |
  | Java has two ways to create programs
|
 |
 |
 |
 |
  | All the programs we've created until now have been applications.
|
 |
 |
 |
 |
  | You can put an application with a GUI in a jar file and then double-click it to run it on your computer.
|
 |
 |
 |
 |
  | An application has full access to all the resources on your computer.
|
 |
 |
 |
 |
  | Applets are programs that run in a web browser like Internet Explorer or Firefox or Safari.
|
 |
 |
 |
 |
  | Usually applets are stored on a server (remote computer) and when you give your browser a URL it loads a web page written in html (hypertext-markup-language) which, in turn, loads and runs the applet in the browser.
|
 |
 |
 |
 |
  | To prevent an applet from stealing personal information, installing or running viruses or damaging your files in any way, applets run in a restricted "sandbox."
|
 |
 |
 |
 |
  | Applets cannot delete files, read the contents of files or create files on the user's system.
|
 |
 |
 |
 |
  | Applets cannot run any other program on the user's system.
|
 |
 |
 |
 |
  | Applets cannot execute operating system procedures on the user's system.
|
 |
 |
 |
 |
  | Applets cannot retrieve information about the user's system or the user's identity.
|
 |
 |
 |
 |
  | Applets cannot make network connections with any system except the server from which the applet was transmitted.
|
 |
 |
 |
 |
  | If an applet displays a window, it will automatically have a message such as "Warning: Applet Window" displayed in it. This lets the user know that the window was not displayed by an application on his or her system.
|
 |
 |
 |
 |
  | As a Java programmer, you have an option of running an applet on your computer in a web browser or in Java's appletviewer. Either way, you need an html file to load the applet. BlueJ creates the necessary html file for you.
|
 |
 |
 |
 |
  | <html> <!-- This file automatically generated by BlueJ Java Development --> <!-- Environment. It is regenerated automatically each time the --> <!-- applet is run. Any manual changes made to file will be lost --> <!-- when the applet is next run inside BlueJ. Save into a --> <!-- directory outside of the package directory if you want to --> <!-- preserve this file. --> <head> <title>CalcApplet Applet</title> </head> <body> <h1>CalcApplet Applet</h1> <hr> <applet code="CalcApplet.class" width=500 height=500 codebase="." archive="file:/Applications/BlueJ%202.5.0/BlueJ.app/Contents/Resources/Java/bluejcore.jar,file:/Applications/BlueJ%202.5.0/BlueJ.app/Contents/Resources/Java/junit.jar,file:/Applications/BlueJ%202.5.0/CIS118_F09/Applets/" alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." > Your browser is ignoring the <APPLET> tag! </applet> <hr> </body> </html>
|
 |
 |
 |
 |
  | The key part of the html file as far as Java is concerned is the part inside the first applet tag:
<applet code="CalcApplet.class" width=500 height=500 codebase="."> </applet>
code="CalcApplet.class" identifies the compiled applet code where execution begins width=500 specifies the width of the applet window height=500 specifies the height of the applet window codebase="." specifies the current directory as the location of the CalcApplet.class file
|
 |
 |
 |
 |
  | Running an applet in BlueJ
|
 |
 |
 |
 |
  | Using appletviewer and setting applet height = 300 and width = 300
|
 |
 |
 |
 |
  | Using a web browser and setting applet height = 300 and width = 300
|
 |
 |
 |
 |
  | import java.applet.*; import java.awt.*; import javax.swing.*;
/* simple applet that prints a greeting on the applet window */ public class Hello extends JApplet { // just about the simplest Java applet public void paint(Graphics g) { g.setColor(Color.red); g.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,72)); g.drawString("Hello, world!", 50, 100); g.drawRect(30,20,450,100); g.setColor(Color.yellow); // graphics demo, oval, rect, lines g.fillOval(100,140,300,150); g.setColor(Color.green); g.drawRect(140,165,220,100); g.setColor(Color.black); g.drawLine(140,165,360,265); g.setColor(Color.blue); g.drawLine(140,265,360,165); } }
/*
Graphic Class
void setColor(Color c)
void clearRect(int x, int y, int width, int height) void drawRect(int x, int y, int width, int height) void drawOval(int x, int y, int width, int height) void drawLine(int x1, int y1, int x2, int y2) void drawString(String s, int x, int y)
void fillRect(int x, int y, int w, int h) void fillArc(int x, int y, int w, int h, int stA, int arcA) void fillOval(int x, int y, int w, int h) void fillRect(int x, int y, int w, int h) void fillRoundRect(int x, int y, int w, int h, int aW, int aH)
*/
|
 |
 |
 |
 |
  | Sample applet code with MouseListener
|
 |
 |
 |
 |
  | import javax.swing.*; import java.awt.*; import java.awt.event.*;
/** * This class demonstrates how a mouse motion listener * can track the location of the mouse pointer. */
public class FollowMe extends JApplet { private int xCoord = 100, yCoord = 100; public void init() { setBackground(Color.white); addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { // Get the mouse pointer's X and Y coordinates. xCoord = e.getX(); yCoord = e.getY(); // Force the paint method to execute. repaint(); } }); } public void paint(Graphics g) { // Call the base class paint method. super.paint(g); // Draw the string at the current mouse location. g.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,36)); g.drawString("Hello", xCoord, yCoord); } }
|
 |
 |
 |
 |
  | //**************************************************** // This applet plays a sound file one time. * //****************************************************
import java.awt.*; import javax.swing.*; import java.awt.event.*;
public class AudioDemo extends JApplet { public void init() { setLayout(new GridLayout(1,1)); JButton btnPlay = new JButton("Play"); btnPlay.setFont(new Font("Serif",Font.BOLD + Font.ITALIC,30)); add(btnPlay); btnPlay.addActionListener(new ActionListener() { // what to do when button pressed public void actionPerformed(ActionEvent event) { play(getDocumentBase(), "JavaJive.wav"); } }); } }
|
 |
 |
 |
 |
  | import javax.swing.*; import java.awt.*;
/** * This class creates a panel that example shapes are * drawn on. */
public class DrawingPanel extends JPanel { private JCheckBox[] checkBoxArray; // Check box array /** * Constructor */ public DrawingPanel(JCheckBox[] cbArray) { // Reference the check box array. checkBoxArray = cbArray; // Set this panel's background color to white. setBackground(Color.WHITE); // Set the preferred size of the panel. setPreferredSize(new Dimension(300, 200)); } /** * paintComponent method */ public void paintComponent(Graphics g) { // Call the superclass paintComponent method. super.paintComponent(g); // Draw the selected shapes. if (checkBoxArray[0].isSelected()) { g.setColor(Color.BLACK); g.drawLine(10, 10, 290, 190); } if (checkBoxArray[1].isSelected()) { g.setColor(Color.BLACK); g.drawRect(20, 20, 50, 50); } if (checkBoxArray[2].isSelected()) { g.setColor(Color.RED); g.fillRect(50, 30, 120, 120); } if (checkBoxArray[3].isSelected()) { g.setColor(Color.BLACK); g.drawOval(40, 155, 75, 50); } if (checkBoxArray[4].isSelected()) { g.setColor(Color.BLUE); g.fillOval(200, 125, 75, 50); } if (checkBoxArray[5].isSelected()) { g.setColor(Color.BLACK); g.drawArc(200, 40, 75, 50, 0, 90); } if (checkBoxArray[6].isSelected()) { g.setColor(Color.GREEN); g.fillArc(100, 155, 75, 50, 0, 90); } } }
|
 |
 |
 |
 |
  | GraphicsWindow class code
|
 |
 |
 |
 |
  | import javax.swing.*; import java.awt.*; import java.awt.event.*;
/** * This class displays a drawing panel and a set of check * boxes that allow the user to select shapes. The selected * shapes are drawn on the drawing panel. */
public class GraphicsWindow extends JApplet { // The following will reference an array of check boxes. private JCheckBox[] checkBoxes; // The titles array contains titles for the check boxes. private String[] titles = { "Line", "Rectangle", "Filled Rectangle", "Oval", "Filled Oval", "Arc", "Filled Arc" };
// The following will reference a panel to contain // the check boxes. private JPanel checkBoxPanel; // The following will reference an instance of the // DrawingPanel class. This will be a panel to draw on. private DrawingPanel drawingPanel; /** * init method */ public void init() { // Build the check box panel. buildCheckBoxPanel(); // Create the drawing panel. drawingPanel = new DrawingPanel(checkBoxes); // Add the check box panel to the east region and // the drawing panel to the center region. add(checkBoxPanel, BorderLayout.EAST); add(drawingPanel, BorderLayout.CENTER); } /** * The buildCheckBoxPanel method creates the array of * check box components and adds them to a panel. */ private void buildCheckBoxPanel() { // Create the panel. checkBoxPanel = new JPanel(); checkBoxPanel.setLayout(new GridLayout(7, 1));
// Create the check box array. checkBoxes = new JCheckBox[7];
// Create the check boxes and add them to the panel. for (int i = 0; i < checkBoxes.length; i++) { checkBoxes[i] = new JCheckBox(titles[i]); checkBoxes[i].addItemListener(new CheckBoxListener()); checkBoxPanel.add(checkBoxes[i]); } }
/** * A private inner class that responds to changes in the * state of the check boxes. */
private class CheckBoxListener implements ItemListener { public void itemStateChanged(ItemEvent e) { drawingPanel.repaint(); } } }
|
 |
 |
 |
 |
  | import javax.swing.*; import java.awt.event.*; import java.awt.*;
/** * This applet demonstrates how the mouse adapter * classes can be used. */ public class DrawBoxes2 extends JApplet { private int currentX = 0; // Current X coordinate private int currentY = 0; // Current Y coordinate private int width = 0; // Rectangle width private int height = 0; // Rectangle height
/** * init method */ public void init() { // Add a mouse listener and a mouse motion listener. addMouseListener(new MyMouseListener()); addMouseMotionListener(new MyMouseMotionListener()); } /** * paint method */ public void paint(Graphics g) { // Call the superclass's paint method. super.paint(g); // Draw a rectangle. g.drawRect(currentX, currentY, width, height); } /** * Mouse listener class */ private class MyMouseListener extends MouseAdapter { public void mousePressed(MouseEvent e) { // Get the mouse cursor's X and Y coordinates. currentX = e.getX(); currentY = e.getY(); } } /** * Mouse Motion listener class */ private class MyMouseMotionListener extends MouseMotionAdapter { public void mouseDragged(MouseEvent e) { // Calculate the size of the rectangle. width = e.getX() - currentX; height = e.getY() - currentY; // Repaint the window. repaint(); } } }
|
 |
 |
 |
 |
  | Applications can be converted to Applets
|
 |
 |
 |
 |
  | Inherit from JApplet and add Applet to the name (not required)
|
 |
 |
 |
 |
  | Replace public class Calc with public class CalcApplet extends JApplet
|
 |
 |
 |
 |
  | Change the main to init and remove parameter and keyword static
|
 |
 |
 |
 |
  | Replace public static void main(String[] args) with public void init()
|
 |
 |
 |
 |
  | Change call to application constructor in main to call to applet constructor in init
|
 |
 |
 |
 |
  | Replace Calc calc = new Calc(); with CalcApplet calc = new CalcApplet();
|
 |
 |
 |
 |
  | Remove parameter in call to super in constructor
|
 |
 |
 |
 |
  | In first line of constructor, call constructer of the parent class: super();
|
 |
 |
 |
 |
  | Remove setDefaultClose call in constructor
|
 |
 |
 |
 |
  | Remove setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
 |
 |
 |
 |
  | Convert this application into an applet
|
 |
 |
 |
 |
  | // ColorMatch.java
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import java.util.*;
public class ColorMatch { static final int WIN_WIDTH = 500; static final int WIN_HEIGHT = 400; static final int MAX_RGB = 256; private JFrame window; private Random r = null; private int randomRed; private int randomGreen; private int randomBlue; private int userRed = 0; private int userGreen = 0; private int userBlue = 0; private JPanel randomPanel = null; private JPanel userPanel = null; private JSlider redSlider = null; private JSlider greenSlider = null; private JSlider blueSlider = null; private JButton showValues = null; private JButton reset = null; public static void main(String args[]) { ColorMatch cm = new ColorMatch(); } public ColorMatch() { window = new JFrame("Color Match"); window.setSize(WIN_WIDTH,WIN_HEIGHT); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setLayout(new BorderLayout()); JPanel panBack = new JPanel(new BorderLayout()); r = new Random(System.currentTimeMillis()); Box hBox = Box.createHorizontalBox(); randomPanel = new JPanel(); randomRed = r.nextInt(MAX_RGB); randomGreen = r.nextInt(MAX_RGB); randomBlue = r.nextInt(MAX_RGB); randomPanel.setBackground(new Color(randomRed,randomGreen,randomBlue)); randomPanel.setBorder(new EtchedBorder()); hBox.add(randomPanel); userPanel = new JPanel(); userPanel.setBackground(new Color(userRed,userGreen,userBlue)); userPanel.setBorder(new EtchedBorder()); hBox.add(userPanel); panBack.add(hBox,BorderLayout.CENTER); JPanel panControls = new JPanel(new GridLayout(2,3));// sliders JLabel jlr = new JLabel("Red",SwingConstants.CENTER); JLabel jlg = new JLabel("Green",SwingConstants.CENTER); JLabel jlb = new JLabel("Blue",SwingConstants.CENTER); redSlider = new JSlider(SwingConstants.HORIZONTAL,0,MAX_RGB-1,0); redSlider.setPaintLabels(true); redSlider.setMajorTickSpacing(50); redSlider.setPaintTicks(true); greenSlider = new JSlider(SwingConstants.HORIZONTAL,0,MAX_RGB-1,0); greenSlider.setPaintLabels(true); greenSlider.setMajorTickSpacing(50); greenSlider.setPaintTicks(true); blueSlider = new JSlider(SwingConstants.HORIZONTAL,0,MAX_RGB-1,0); blueSlider.setPaintLabels(true); blueSlider.setMajorTickSpacing(50); blueSlider.setPaintTicks(true); panControls.add(jlr); panControls.add(jlg); panControls.add(jlb); panControls.add(redSlider); panControls.add(greenSlider); panControls.add(blueSlider); panBack.add(panControls,BorderLayout.SOUTH); window.add(panBack,BorderLayout.CENTER); JPanel panButtons = new JPanel(); panButtons.setLayout(new GridLayout(1,2)); showValues = new JButton("Show Values"); reset = new JButton("Reset"); BevelBorder edge = new BevelBorder(BevelBorder.RAISED); showValues.setBorder(edge); reset.setBorder(edge); panButtons.add(showValues); panButtons.add(reset); window.add(panButtons,BorderLayout.SOUTH); redSlider.addChangeListener(new ChangeListener() // listeners { public void stateChanged(ChangeEvent e) { userRed = redSlider.getValue(); userPanel.setBackground(new Color(userRed,userGreen,userBlue)); } }); greenSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { userGreen = greenSlider.getValue(); userPanel.setBackground(new Color(userRed,userGreen,userBlue)); } }); blueSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { userBlue = blueSlider.getValue(); userPanel.setBackground(new Color(userRed,userGreen,userBlue)); } }); showValues.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String s1 = "Red: " + format(randomRed,3); String s2 = "Red: " + format(userRed,3); String s3 = "Green: " + format(randomGreen,3); String s4 = "Green: " + format(userGreen,3); String s5 = "Blue: " + format(randomBlue,3); String s6 = "Blue: " + format(userBlue,3); String s = " "; String n = "\n"; JOptionPane.showMessageDialog(null,s1+s+s2+n+s3+s+s4+n+s5+s+s6); } }); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { randomRed = r.nextInt(MAX_RGB); randomGreen = r.nextInt(MAX_RGB); randomBlue = r.nextInt(MAX_RGB); randomPanel.setBackground(new Color(randomRed,randomGreen,randomBlue)); userRed = 0; userGreen = 0; userBlue = 0; userPanel.setBackground(new Color(userRed,userGreen,userBlue)); redSlider.setValue(userRed); greenSlider.setValue(userGreen); blueSlider.setValue(userBlue); } });
window.setVisible(true); }
public String format(int value, int field) { String s = (new Integer(value)).toString(); while (s.length() < field) { s = " " + s; } return s; } }
|
 |
 |
|


 |
 |
 |