daily pastebin goal
40%
SHARE
TWEET

x

a guest Dec 10th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package test;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Dimension;
  5. import java.awt.EventQueue;
  6. import java.awt.Graphics;
  7. import java.awt.Toolkit;
  8.  
  9. import javax.swing.*;
  10. import javax.swing.event.ChangeEvent;
  11. import javax.swing.event.ChangeListener;
  12.  
  13. public class Kreski3 extends JFrame {
  14.     MojKomponent komponent;
  15.     int n = 11;
  16.     public class MojKomponent extends JComponent{
  17.  
  18.         @Override
  19.         protected void paintComponent(Graphics g) {
  20.            
  21.             int w = getWidth();
  22.             int h = getHeight();
  23.            
  24.             g.drawRect(w/4, h/4, w/2, h/2);
  25.            
  26.             g.drawLine(arg0, arg1, arg2, arg3);
  27.            
  28.             super.paintComponent(g);
  29.         }
  30.        
  31.     }
  32.    
  33.     public Kreski3(String string) {
  34.         super(string);
  35.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  36.         Toolkit kit = Toolkit.getDefaultToolkit();
  37.         Dimension d = kit.getScreenSize();
  38.         setBounds(d.width/4, d.height/4, d.width/2, d.height/2);
  39.         add(komponent = new MojKomponent());
  40.        
  41.         final JSlider slider = new JSlider(1,50,n);
  42.         add(slider, BorderLayout.SOUTH);
  43.        
  44.         slider.addChangeListener(new ChangeListener() {
  45.             @Override
  46.             public void stateChanged(ChangeEvent e) {
  47.                 n = slider.getValue();
  48.                 komponent.repaint();
  49.                
  50.             }
  51.         });
  52.  
  53.         setVisible(true);
  54.     }
  55.  
  56.     public static void main(String[] args) {
  57.         EventQueue.invokeLater(new Runnable() {
  58.             @Override
  59.             public void run() {
  60.                 new Kreski3("Kreski");
  61.             }
  62.         });
  63.     }
  64.  
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top