Created
December 20, 2017 14:56
-
-
Save sugiartocokrowibowo/2d686aee8e7a12619ef1b02ecae955ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package latihan1; | |
import java.awt.Color; | |
import java.awt.EventQueue; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
import javax.swing.JComponent; | |
import javax.swing.JFrame; | |
public class Main extends JFrame { | |
public Main(){ | |
initUI(); | |
} | |
private void initUI() { | |
add(new Canvas()); | |
setTitle("Computer Graphics"); | |
setSize(1024, 600); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setLocationRelativeTo(null); | |
} | |
public static void main(String[] args){ | |
EventQueue.invokeLater(new Runnable(){ | |
public void run() { | |
Main unsulbar = new Main(); | |
unsulbar.setVisible(true); | |
} | |
}); | |
} | |
public class Canvas extends JComponent { | |
public void paint(Graphics g) { | |
Graphics2D g2d = (Graphics2D) g; | |
int tinggi = (int)(this.getHeight()/4.0f); | |
int lebar = (int)(this.getWidth()/5.0f); | |
int xo = 0; | |
int yo = 0; | |
g2d.setColor(Color.decode("#3498db")); | |
g2d.fillRect(xo, yo, (int)lebar, (int)tinggi); | |
g2d.dispose(); | |
//--------------------------------------------------------------------------------------------------- | |
}//end of paint(Graphics g) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment