Skip to main content

Posts

Showing posts from March, 2018

Points with example 1

                 Points in java with example Points The most simple graphics primitive is point. It is a single dot on the window. There is no method to draw a point in Swing. To draw a point, we use the drawLine() method. We use one point twice. package PRACTICEPROGRAM; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.util.Random; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; class DrawPanel extends JPanel {     public void paintComponent(Graphics g) {         super.paintComponent(g);         Graphics2D g2d = (Graphics2D) g;         g2d.setColor(Color.blue);      ...

MVC Example 1

                        Swing MVC Example in java Java Swing first programs In this chapter, we will program our first programs in Swing toolkit. The examples are going  to be very simple. We will cover some basic functionality. Our first example In our first example, we will show a basic window. import javax.swing.JFrame; public class Simple extends JFrame { public Simple() { setSize(300, 200); setTitle("Simple"); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { Simple simple = new Simple(); simple.setVisible(true); } } While this code is very small, the application window can do quite a lot. It can be resized, maximized, minimized. All the complexity that comes with it has been hidden from the application programmer. import javax.swing.JFrame; Here we import the JFrame widget. It is a toplevel container, which is used for plac...