Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.lang.*;
- class satframe extends JFrame {
- public static void main (String []args ) {
- satframe frame = new satframe();
- frame.setVisible(true);
- }
- public satframe( ) { //DO NOT TOUCH!!!
- //set the frame default properties
- setTitle ( "Satellite Upload");
- setSize ( 1024,600 );
- setLocationRelativeTo ( null );
- setResizable (false);
- Image img = Toolkit.getDefaultToolkit().getImage( "img.png" );
- setIconImage ( img );
- //register 'Exit upon closing' as a default close operation
- setDefaultCloseOperation( EXIT_ON_CLOSE );
- changeBkColor( );
- }
- private void changeBkColor() {
- //change background color to green
- Color myGreenColor = new Color(0, 100, 0); //a dark green
- Container contentPane = getContentPane();
- contentPane.setBackground(myGreenColor);
- //set layout manager to null
- contentPane.setLayout(null);
- //make the map, and align it to the left
- ImageIcon pic = new ImageIcon("pic.png");
- JLabel map = new JLabel(pic);
- map.setBounds(0, 0, 600, 600);
- map.setBorder(BorderFactory.createRaisedBevelBorder());
- contentPane.add( map );
- //makes the progress bar
- final JProgressBar Bar = new JProgressBar(0, 900);
- Bar.setValue(0);
- Bar.setStringPainted(true);
- Bar.setBounds(700, 75, 206, 40);
- Bar.setBorder(BorderFactory.createRaisedBevelBorder());
- contentPane.add( Bar );
- //create and add start button
- JButton startButton = new JButton ("Start File Download");
- startButton.setBounds(700, 200, 206, 100);
- startButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- Thread t1 = new Thread( new Runnable() {
- public void run() {
- int b = 0;
- if (b == 0) {
- JOptionPane.showMessageDialog(null, "Starting upload.", "Starting Upload", JOptionPane.INFORMATION_MESSAGE);
- try {
- while (b < 900) {
- b++;
- Bar.setValue (b);
- Thread.sleep(1000L);
- final int u = b;
- Bar.setValue(u);
- }
- } catch (InterruptedException iex) {
- JOptionPane.showMessageDialog (null, "The upload has stopped.", "Upload Failed", JOptionPane.ERROR_MESSAGE);
- }
- } if (b == 900) {
- JOptionPane.showMessageDialog(null, "The upload has already completed.", "You fail.", JOptionPane.ERROR_MESSAGE);
- } if (b != 0 && b != 900) {
- JOptionPane.showMessageDialog(null, "There is already an upload in progress.", "You fail.", JOptionPane.ERROR_MESSAGE);
- }
- JOptionPane.showMessageDialog(null, "Upload Complete!", "Upload successful!", JOptionPane.INFORMATION_MESSAGE);
- }
- });
- t1.start();
- }
- });
- contentPane.add( startButton );
- //create and add stop button
- JButton stopButton = new JButton ("Stop File Download");
- stopButton.setBounds(700, 375, 206, 100);
- stopButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int d = 0;
- int f = Bar.getValue();
- if (f != 900 && f != 0) {
- Bar.setValue (d);
- JOptionPane.showMessageDialog(null, "Upload stopped.");
- System.exit(0);
- }
- if (f == 900) {
- JOptionPane.showMessageDialog(null, "You cannot stop the upload, for it has already been uploaded.", "You fail.", JOptionPane.ERROR_MESSAGE);
- }
- if (f == 0) {
- JOptionPane.showMessageDialog(null, "There is no upload to stop.", "You fail.", JOptionPane.ERROR_MESSAGE);
- }
- }
- });
- contentPane.add( stopButton );
- }
- }
Add Comment
Please, Sign In to add comment