Change the name below
GraphicsExample example = new LineStyles();All the examples implement GraphicsExample.java
Test5.java// Test5.java
import java.awt.Graphics;
import java.awt.FontMetrics;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class Test5 extends JPanel
{
GraphicsExample example = new LineStyles();
public void paintComponent(Graphics g)
{
super.paintComponent( g );
this.setBackground(Color.WHITE);
int width = getWidth();
int height = getHeight();
example.draw((Graphics2D) g, this); // ask example to draw itself
}
public static void main( String args[] )
{
Test5 panel = new Test5();
String name = panel.example.getName();
JFrame application = new JFrame(name);
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel);
int width = panel.example.getWidth();
int height =panel.example.getHeight();
application.setSize(width,height);
application.setVisible(true);
}
}
GraphicsExample.java
import java.awt.*;
/**
* This interface defines the methods that must be implemented by an
* object that is to be displayed by the GraphicsExampleFrame object
*/
public interface GraphicsExample {
public String getName(); // Return the example name
public int getWidth(); // Return its width
public int getHeight(); // Return its height
public void draw(Graphics2D g, Component c); // Draw the example
}
Maintained by John Loomis, updated Tue Feb 04 18:19:46 2020