Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Draw-a-pixel/Java/draw-a-pixel-2.java
Normal file
33
Task/Draw-a-pixel/Java/draw-a-pixel-2.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class DrawAPixel extends JPanel{
|
||||
private BufferedImage puffer;
|
||||
private JFrame window;
|
||||
private Graphics g;
|
||||
public DrawAPixel() {
|
||||
window = new JFrame("Red Pixel");
|
||||
window.setSize(320, 240);
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
window.setLayout(null);
|
||||
setBounds(0, 0, 320, 240);
|
||||
window.add(this);
|
||||
window.setVisible(true);
|
||||
}
|
||||
@Override
|
||||
public void paint(Graphics gr) {
|
||||
if(g == null) {
|
||||
puffer = (BufferedImage) createImage(getWidth(), getHeight());
|
||||
g = puffer.getGraphics();
|
||||
}
|
||||
g.setColor(new Color(255, 0, 0));
|
||||
g.drawRect(100, 100, 1, 1);
|
||||
gr.drawImage(puffer, 0, 0, this);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
new DrawAPixel();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue