Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import javax.swing.JPanel;
- public class AClass extends JPanel {
- OtherClass oc = new OtherClass();
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- setBackground(Color.BLACK);
- oc.paintComponent(g);
- g.setColor(Color.WHITE);
- g.setFont(new Font("TimesRoman", Font.PLAIN, 40));
- g.drawString("getHeight() (in AClass): " + getHeight() + " Pixels", 50, 50);
- oc.setGraphicsHeight(getHeight());
- }
- }
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import javax.swing.JPanel;
- public class OtherClass extends JPanel {
- int y;
- int height;
- public OtherClass() {
- y = height;
- }
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(Color.BLUE);
- g.setColor(Color.WHITE);
- g.setFont(new Font("TimesRoman", Font.PLAIN, 40));
- g.drawString("y (Height of Graphic in OtherClass): " + y + " Pixels", 50, 140);
- }
- public void setGraphicsHeight(int h) {
- height = h;
- }
- }
- import javax.swing.JFrame;
- public class Draw {
- static AClass ac = new AClass();
- public static void main(String[] argv) {
- JFrame p = new JFrame();
- p.setSize(800, 240);
- p.add(ac);
- p.setTitle("Height Dimensions");
- p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- p.setLocationRelativeTo(null);
- p.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment