Last active
August 29, 2015 14:21
-
-
Save ornirus/032fd2b2f81f996ef7e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class DrawExample extends JFrame | |
implements ActionListener { | |
private JButton button; | |
private JPanel panel; | |
public static void main(String[] args) { | |
DrawExample frame = new DrawExample(); | |
frame.setSize(400, 300); | |
frame.createGUI(); | |
frame.setVisible(true); | |
} | |
private void createGUI() { | |
setDefaultCloseOperation(EXIT_ON_CLOSE); | |
Container window = getContentPane(); | |
window.setLayout(new FlowLayout() ); | |
panel = new JPanel(); | |
panel.setPreferredSize(new Dimension(300, 200)); | |
panel.setBackground(Color.white); | |
window.add(panel); | |
button = new JButton("Press me"); | |
window.add(button); | |
button.addActionListener(this); | |
} | |
public void actionPerformed(ActionEvent event) { | |
Graphics paper = panel.getGraphics(); | |
paper.drawLine(0, 0, 100, 100); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
public abstract class Shape { | |
protected int x, y ; | |
protected int size; | |
public void moveRight() { | |
x = x + 10; | |
} | |
public abstract void display(Graphics paper); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment