Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Main
- public class Main
- {
- public static void main(String[] args)
- {
- new Frame();
- }
- }
- ///MyFrame
- import java.awt.BorderLayout;
- import javax.swing.JFrame;
- public class Frame
- {
- Frame()
- {
- JFrame f = new JFrame();
- f.setSize(400, 400);
- f.setLayout(new BorderLayout());
- f.setLocationRelativeTo(null);
- f.add(new Button(), BorderLayout.SOUTH);
- f.add(new Sehen(), BorderLayout.NORTH);
- f.setVisible(true);
- }
- }
- //Button
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JPanel;
- public class Button extends JPanel implements ActionListener
- {
- private int zahl = 0;
- JButton testBut = new JButton("hi");
- Sehen mies = new Sehen();
- Button()
- {
- this.add(testBut);
- testBut.addActionListener(this);
- }
- protected int getZahl()
- {
- return this.zahl;
- }
- protected void setZahl(int zahl)
- {
- this.zahl = zahl;
- }
- @Override
- public void actionPerformed(ActionEvent e)
- {
- if(e.getSource() == testBut)
- {
- zahl++;
- mies.setZahl(zahl);
- mies.repaint();
- }
- }
- }
- //Sehen
- import java.awt.Graphics;
- import javax.swing.JPanel;
- public class Sehen extends JPanel
- {
- private int zahl = 0;
- protected void setZahl(int zahl)
- {
- this.zahl = zahl;
- }
- @Override
- protected void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- System.out.println(zahl);
- g.fillRect(0, 0, zahl, 10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement