import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.*;
import javax.swing.*;public class DrawTest
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class DrawFrame extends JFrame
{
private JButton btn1,btn2;
private DrawComponent component;
public DrawFrame()
{
setTitle("DrawTest");
setSize(400,400);
btn1=new JButton("放大");
btn2=new JButton("缩小");
btn1.addActionListener(new ButtonActionListener());
Panel controlPanel=new Panel();
controlPanel.add(btn1);
controlPanel.add(btn2);
component = new DrawComponent();
add(controlPanel,BorderLayout.NORTH);
add(component,BorderLayout.CENTER);
}
class ButtonActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JButton button = (JButton)e.getSource();
if(button==btn1){
}
}
}
}
class DrawComponent extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
Rectangle2D rect = new Rectangle2D.Double(100,100,200,200);
g2.draw(rect);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.*;
import javax.swing.*;public class DrawTest
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class DrawFrame extends JFrame
{
private JButton btn1,btn2;
private DrawComponent component;
public DrawFrame()
{
setTitle("DrawTest");
setSize(400,400);
btn1=new JButton("放大");
btn2=new JButton("缩小");
btn1.addActionListener(new ButtonActionListener());
Panel controlPanel=new Panel();
controlPanel.add(btn1);
controlPanel.add(btn2);
component = new DrawComponent();
add(controlPanel,BorderLayout.NORTH);
add(component,BorderLayout.CENTER);
}
class ButtonActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JButton button = (JButton)e.getSource();
if(button==btn1){
}
}
}
}
class DrawComponent extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
Rectangle2D rect = new Rectangle2D.Double(100,100,200,200);
g2.draw(rect);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.*;
import javax.swing.*;public class DrawTest
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class DrawFrame extends JFrame
{
private JButton btn1,btn2;
private DrawComponent component;
public DrawFrame()
{
setTitle("DrawTest");
setSize(400,400);
btn1=new JButton("放大");
btn2=new JButton("缩小");
btn1.addActionListener(new ButtonActionListener());
btn2.addActionListener(new ButtonActionListener()); Panel controlPanel=new Panel();
controlPanel.add(btn1);
controlPanel.add(btn2);
component = new DrawComponent();
add(controlPanel,BorderLayout.NORTH);
add(component,BorderLayout.CENTER);
}
class ButtonActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JButton button = (JButton)e.getSource();
if(button==btn1){
component.zoomIn(13);
component.repaint();
}
if(button==btn2){
component.zoomOut(13);
component.repaint();
}
}
}
}
class DrawComponent extends JComponent{
int w=200,h=200;
public void zoomIn(int zoom){
w =w+zoom;
h =w+zoom;
}
public void zoomOut(int zoom){
w =w-zoom;
h =w-zoom;
} public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Rectangle2D rect = new Rectangle2D.Double(100,100,w,h);
g2.draw(rect);
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.*;
import javax.swing.*;public class DrawTest
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class DrawFrame extends JFrame
{
private JButton btn1,btn2;
private DrawComponent component;
public DrawFrame()
{
setTitle("DrawTest");
setSize(400,400);
btn1=new JButton("放大");
btn2=new JButton("缩小");
btn1.addActionListener(new ButtonActionListener());
btn2.addActionListener(new ButtonActionListener()); Panel controlPanel=new Panel();
controlPanel.add(btn1);
controlPanel.add(btn2);
component = new DrawComponent();
add(controlPanel,BorderLayout.NORTH);
add(component,BorderLayout.CENTER);
}
class ButtonActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JButton button = (JButton)e.getSource();
if(button==btn1){
component.zoomIn(13);
component.repaint();
}
if(button==btn2){
component.zoomOut(13);
component.repaint();
}
}
}
}
class DrawComponent extends JComponent{
int x=100,y=100,w=200,h=200;
public void zoomIn(int zoom){
x =x-zoom;
y =y-zoom;
w =w+zoom*2;
h =w+zoom*2;
}
public void zoomOut(int zoom){
x =x+zoom;
y =y+zoom;
w =w-zoom*2;
h =w-zoom*2;
} public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Rectangle2D rect = new Rectangle2D.Double(x,y,w,h);
g2.draw(rect);
}
}