/*
* 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
}
没有合适的资源?快使用搜索试试~ 我知道了~
java画电路图
共48个文件
class:23个
java:15个
xml:4个
需积分: 49 13 下载量 179 浏览量
2012-11-21
15:50:27
上传
评论 1
收藏 39KB ZIP 举报
温馨提示
利用面向对象的思想,能够实现利用线、矩形等画出简易的电路图,并且对于电路图能够放大缩小。
资源推荐
资源详情
资源评论
收起资源包目录
画图.zip (48个子文件)
画图
src
画图
Components.java 613B
PCapcitor.java 658B
mainFrame.form 1KB
Figure.java 730B
Triangle.java 963B
PNPTransistor.java 894B
Ground.java 665B
PowerSupply.java 818B
Circle.java 830B
Rectangle.java 883B
DrawPanel.java 2KB
DrawPanel.form 1KB
NPCapcitor.java 1KB
Resistor.java 965B
NPNTransistor.java 886B
mainFrame.java 7KB
Line.java 938B
build
classes
画图
Ground.class 838B
Line.class 944B
Component.class 696B
DrawPanel$1.class 733B
Resistor.class 1KB
mainFrame.class 3KB
NPCapcitor.class 1KB
Triangle.class 787B
mainFrame$2.class 787B
Main.class 369B
NPNTransistor.class 989B
mainFrame$5.class 2KB
Components.class 699B
PCapcitor.class 854B
mainFrame$1.class 530B
DrawPanel.class 2KB
PNPTransistor.class 1015B
Circle.class 830B
mainFrame$3.class 787B
PowerSupply.class 848B
Figure.class 862B
Rectangle.class 878B
mainFrame$4.class 676B
nbproject
genfiles.properties 455B
build-impl.xml 32KB
project.properties 2KB
project.xml 576B
private
private.properties 185B
private.xml 211B
build.xml 3KB
manifest.mf 85B
test
共 48 条
- 1
资源评论
wangchen0899
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功