Skip to content

Instantly share code, notes, and snippets.

@ornirus
Last active August 29, 2015 14:21
Show Gist options
  • Save ornirus/032fd2b2f81f996ef7e7 to your computer and use it in GitHub Desktop.
Save ornirus/032fd2b2f81f996ef7e7 to your computer and use it in GitHub Desktop.
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);
}
}
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