/*
* mainFrame.java
*
* Created on 2011年12月14日, 下午9:16
*/
package 画图;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JToolBar;
import javax.swing.event.ChangeEvent;
/**
*
* @author Administrator
*/
public class mainFrame extends javax.swing.JFrame {
private DrawPanel drawingArea;
private int width,height;
private JLabel jLabel1;
static double scale;
/** Creates new form mainFrame */
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new mainFrame().setVisible(true);
}
});
}
public mainFrame() {
initComponents();
this.setLocation(200,200);
drawingArea=new DrawPanel();
width = 850;
height = 700; //画图区域
scale=1.00;
this.setContentPane(drawingArea);
setSize(width, height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置窗体退出时操作
//JPanel panel = new JPanel();// 创建面板
//drawingArea.add(panel, BorderLayout.SOUTH);// 将新面板放置在内容面板南面
setVisible(true);
JToolBar bar = new JToolBar();
//bar.setForeground(Color.RED);
bar.setBackground(Color.BLACK);
JButton enlarge = new JButton("1 Zoom in");
//enlargeMenu.setBackground(Color.black);
//enlargeMenu.setMnemonic('F');
//新建文件菜单项
//JMenu reduceMenu = new JMenu("2 Zoom out");
//JMenu exitMenu = new JMenu("3 Exit");
//newItem.setMnemonic('N');
//enlargeMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));
enlarge.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
//如果被触发,则调用新建文件函数段
scale=1.3;
jLabel1.repaint();
}
});
JButton reduce = new JButton("2 Zoom out");
reduce.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
//如果被触发,则调用新建文件函数段
scale=0.5;
jLabel1.repaint();
}
});
JButton exit = new JButton("3 Exit");
exit.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
bar.add(enlarge);
bar.add(reduce);
bar.add(exit);
drawingArea.add(bar,BorderLayout.NORTH);
jLabel1 =new JLabel("")
{
@Override
public void paint(Graphics g)
{
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.scale(scale, scale);
int x1=100;
int y1=100;
Figure f=new Line(x1,y1,300,0);
f.draw(g2d);
f=new Line(x1,y1,130,1);
f.draw(g2d);
Components c=new PowerSupply();
c.setXY(x1, y1+130);
c.draw(g2d);
f=new Line(x1,y1+165,135,1);
f.draw(g2d);
f=new Line(x1,y1+300,300,0);
f.draw(g2d);
f=new Line(x1+50,y1,50,1);
f.draw(g2d);
c=new Resistor(10,10,40);
c.setXY(x1+50, y1+50);
c.draw(g2d);
f=new Line(x1+50,y1+110,90,1);
f.draw(g2d);
c=new PCapcitor();
c.setXY(x1+50,y1+200);
c.draw(g2d);
f=new Line(x1+50,y1+240,60,1);
f.draw(g2d);
c=new Resistor(30, 10, 40);
c.setXY(x1+100, y1);
c.draw(g2d);
c=new Resistor(30,10,40);
c.setXY(x1+100,y1+100);
c.draw(g2d);
c=new Resistor(30,10,40);
c.setXY(x1+100, y1+200);
c.draw(g2d);
f=new Line(x1+300,y1,40,1);
f.draw(g2d);
c=new PNPTransistor();
c.setXY(x1+250,y1+40);
c.draw(g2d);
f=new Line(x1+300,y1+120,20,1);
f.draw(g2d);
c=new NPNTransistor();
c.setXY(x1+250,y1+140);
c.draw(g2d);
c=new Resistor(20, 10, 40);
c.setXY(x1+300, y1+220);
c.draw(g2d);
f=new Line(x1+100,y1+80,150,0);
f.draw(g2d);
f=new Line(x1+100,y1+180,150,0);
f.draw(g2d);
c=new Ground();
c.setXY(x1+130,y1+300);
c.draw(g2d);
c=new NPCapcitor(0,40,20);
c.setXY(x1+300, y1+130);
c.draw(g2d);
c=new NPCapcitor(1,40,20);
c.setXY(x1+150, y1+180);
c.draw(g2d);
}
};
drawingArea.add(jLabel1, BorderLayout.CENTER);// 在内容面板中央增加标签
}
/* @Override
public void paint(Graphics g)
{
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
//g2d.setPaint(Color.WHITE);
//g2d.setStroke(new BasicStroke(1.0f,BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
// g2d.drawLine(310, 310, 340, 340);
// Line l=new Line();
// l.draw(g2d);
Triangle c=new Triangle();
c.draw(g2d);
g2d.scale(1.3,1.3);
c.draw(g2d);
}*/
protected void do_slider_stateChanged(ChangeEvent e)
{
jLabel1.repaint(); // 滑动滑块时重新绘制标签
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}