Draxion

Two Different Dimensions

Mar 24th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import javax.swing.JPanel;
  5.  
  6.  
  7. public class AClass extends JPanel {
  8.  
  9.     OtherClass oc = new OtherClass();
  10.    
  11.  
  12.     public void paintComponent(Graphics g) {
  13.         super.paintComponent(g);
  14.        
  15.         setBackground(Color.BLACK);
  16.         oc.paintComponent(g);
  17.         g.setColor(Color.WHITE);
  18.         g.setFont(new Font("TimesRoman", Font.PLAIN, 40));
  19.         g.drawString("getHeight() (in AClass): " + getHeight() + " Pixels", 50, 50);
  20.         oc.setGraphicsHeight(getHeight());
  21.     }
  22. }
  23.  
  24. import java.awt.Color;
  25. import java.awt.Font;
  26. import java.awt.Graphics;
  27. import javax.swing.JPanel;
  28.  
  29. public class OtherClass extends JPanel {
  30.     int y;
  31.     int height;
  32.    
  33.     public OtherClass() {
  34.         y = height;
  35.     }
  36.    
  37.     public void paintComponent(Graphics g) {
  38.         super.paintComponent(g);
  39.         g.setColor(Color.BLUE);
  40.         g.setColor(Color.WHITE);
  41.         g.setFont(new Font("TimesRoman", Font.PLAIN, 40));
  42.         g.drawString("y (Height of Graphic in OtherClass): " + y + " Pixels", 50, 140);
  43.    
  44.     }
  45.    
  46.     public void setGraphicsHeight(int h) {
  47.         height = h;
  48.     }
  49. }
  50.  
  51. import javax.swing.JFrame;
  52.  
  53. public class Draw {
  54.     static AClass ac = new AClass();
  55.     public static void main(String[] argv) {
  56.    
  57.  
  58.     JFrame p = new JFrame();
  59.    
  60.     p.setSize(800, 240);
  61.     p.add(ac);
  62.     p.setTitle("Height Dimensions");
  63.     p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  64.     p.setLocationRelativeTo(null);
  65.     p.setVisible(true);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment