Guest User

Untitled

a guest
Apr 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.52 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.lang.*;
  5.  
  6. class satframe extends JFrame {
  7.  
  8.     public static void main (String []args ) {
  9.         satframe frame = new satframe();
  10.         frame.setVisible(true);
  11.     }
  12.    
  13.     public satframe( ) { //DO NOT TOUCH!!!
  14.         //set the frame default properties
  15.         setTitle    ( "Satellite Upload");
  16.         setSize ( 1024,600 );
  17.         setLocationRelativeTo ( null );
  18.         setResizable (false);
  19.         Image img = Toolkit.getDefaultToolkit().getImage( "img.png" );
  20.         setIconImage ( img );
  21.         //register 'Exit upon closing' as a default close operation
  22.         setDefaultCloseOperation( EXIT_ON_CLOSE );
  23.  
  24.         changeBkColor( );
  25.     }
  26.     private void changeBkColor() {
  27.         //change background color to green
  28.         Color myGreenColor = new Color(0, 100, 0); //a dark green
  29.         Container contentPane = getContentPane();
  30.         contentPane.setBackground(myGreenColor);
  31.         //set layout manager to null
  32.         contentPane.setLayout(null);
  33.         //make the map, and align it to the left
  34.         ImageIcon pic = new ImageIcon("pic.png");
  35.         JLabel map = new JLabel(pic);
  36.         map.setBounds(0, 0, 600, 600);
  37.         map.setBorder(BorderFactory.createRaisedBevelBorder());
  38.         contentPane.add( map );
  39.         //makes the progress bar
  40.         final JProgressBar Bar = new JProgressBar(0, 900);
  41.         Bar.setValue(0);
  42.         Bar.setStringPainted(true);
  43.         Bar.setBounds(700, 75, 206, 40);
  44.         Bar.setBorder(BorderFactory.createRaisedBevelBorder());
  45.         contentPane.add( Bar );
  46.         //create and add start button
  47.         JButton startButton = new JButton ("Start File Download");
  48.         startButton.setBounds(700, 200, 206, 100);
  49.         startButton.addActionListener(new ActionListener() {
  50.             public void actionPerformed(ActionEvent e) {
  51.                 Thread t1 = new Thread( new Runnable() {
  52.                     public void run() {
  53.                         int b = 0;
  54.                         if (b == 0) {
  55.                             JOptionPane.showMessageDialog(null, "Starting upload.", "Starting Upload", JOptionPane.INFORMATION_MESSAGE);
  56.                             try {
  57.                                 while (b < 900) {
  58.                                     b++;
  59.                                     Bar.setValue (b);
  60.                                     Thread.sleep(1000L);
  61.                                     final int u = b;
  62.                                     Bar.setValue(u);
  63.                                 }
  64.                             } catch (InterruptedException iex) {
  65.                                 JOptionPane.showMessageDialog (null, "The upload has stopped.", "Upload Failed", JOptionPane.ERROR_MESSAGE);
  66.                             }
  67.                         } if (b == 900) {
  68.                             JOptionPane.showMessageDialog(null, "The upload has already completed.", "You fail.", JOptionPane.ERROR_MESSAGE);
  69.                         } if (b != 0 && b != 900) {
  70.                             JOptionPane.showMessageDialog(null, "There is already an upload in progress.", "You fail.", JOptionPane.ERROR_MESSAGE);
  71.                         }
  72.                         JOptionPane.showMessageDialog(null, "Upload Complete!", "Upload successful!", JOptionPane.INFORMATION_MESSAGE);
  73.                     }  
  74.                 });
  75.                 t1.start();
  76.             }
  77.         });
  78.         contentPane.add( startButton );
  79.         //create and add stop button
  80.         JButton stopButton = new JButton ("Stop File Download");
  81.         stopButton.setBounds(700, 375, 206, 100);
  82.         stopButton.addActionListener(new ActionListener() {
  83.             public void actionPerformed(ActionEvent e) {
  84.                 int d = 0;
  85.                 int f = Bar.getValue();
  86.                 if (f != 900 && f != 0) {
  87.                     Bar.setValue (d);
  88.                     JOptionPane.showMessageDialog(null, "Upload stopped.");
  89.                     System.exit(0);
  90.                 }
  91.                 if (f == 900) {
  92.                     JOptionPane.showMessageDialog(null, "You cannot stop the upload, for it has already been uploaded.", "You fail.", JOptionPane.ERROR_MESSAGE);
  93.                 }
  94.                 if (f == 0) {
  95.                     JOptionPane.showMessageDialog(null, "There is no upload to stop.", "You fail.", JOptionPane.ERROR_MESSAGE);
  96.                 }
  97.             }
  98.         });
  99.         contentPane.add( stopButton );
  100.     }
  101. }
Add Comment
Please, Sign In to add comment