我只是不知道怎么把中间的editor部分变成一个可以Panel,其他的再自己研究,请高人赐教
解决方案 »
- 经典逻辑推理题!一道!试试你的能力!
- 运行一个桌面的程序出现的异常,大家帮忙看看有没有好的解决方案
- eclipse 中 spring 如何导入?
- 两个问题:内存泄露及调用函数
- 请各位朋友指教!如何把JAVA编写的程序做成Windows下的.exe可执行程序呢?谢谢喽!!!
- HttpClient能否直接获取服务器的request对象
- 请教OutOfMemoryError问题
- 应该属于类路径的设置问题
- 怎样判断是否是GB2312里的文字
- 关于数组的问题希望大牛给小白解答一下
- 高分求java绘图程序源代码
- redhat7.3下,java程序打印中文直接用java命令执行正常,用crontab执行为乱码
希望能对你有所帮助
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.awt.*;
import java.util.*;
public class MainFrame extends JFrame implements MouseMotionListener,MouseListener
//ActionListener
{ JPanel desktop;
JMenuBar MBar;
Vector dot=new Vector();
boolean beginDraw = false;
Vector v = new Vector();
public MainFrame(){ super("Draw");
buildContent();
buildMenu();
addMouseMotionListener(this);
addMouseListener(this);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
quit();
}
});//end of addWindowListener
}//end of main protected void buildContent() {
desktop = new JPanel();
getContentPane().add(desktop,BorderLayout.CENTER);
desktop.setBackground(Color.white);
}//end of buildContent() protected void buildMenu(){
JPopupMenu.setDefaultLightWeightPopupEnabled(false); MBar = new JMenuBar();
MBar.setOpaque(true);
JMenu mfile = buildFileMenu(); MBar.add(mfile);
setJMenuBar(MBar);
}//end of bulidMenu() public void quit(){
System.exit(0);
}//end of quit() public JMenu buildFileMenu() {
JMenu file = new JMenu("File"); JMenuItem open = new JMenuItem("Open");
JMenuItem save= new JMenuItem("Save");
JMenuItem clear = new JMenuItem("Clear");
JMenuItem exit = new JMenuItem("Exit");
file.add(open);
file.add(save);
file.add(clear);
file.addSeparator();
file.add(exit);
open.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{
try{
FileInputStream fis=new FileInputStream("Save.ser");
ObjectInputStream ois=new ObjectInputStream(fis);
v=(Vector) ois.readObject();
ois.close();
repaint();
}catch(Exception t){}
}});
save.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{
try{
FileOutputStream fos=new FileOutputStream("Save.ser");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(v);
oos.close();
}catch(Exception t){}
}});
exit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{
System.exit(0);
}});
clear.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
{
v.clear();
repaint();
}});
return file;
}//end of buildFileMenu()
public void mouseMoved(MouseEvent e){}public void mouseDragged(MouseEvent e)
{
Point p = null;
if(beginDraw)
{
p = new Point(e.getX(), e.getY());
dot.add(p);
Graphics g = getGraphics();
draw_buf(g);
}
}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e)
{
dot.clear();
beginDraw = true;
}
public void mouseReleased(MouseEvent e)
{
beginDraw = false;
v.add(dot.clone());
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.blue);
for(int i = 0; i < v.size(); i++)
{
Vector temporary = (Vector)v.get(i);
for(int loop=0;loop<temporary.size()-1;loop++)
{
Point p = (Point)temporary.get(loop);
Point p1 = (Point)temporary.get(loop + 1);
g.drawLine(p.x,p.y,p1.x,p1.y);
}
}
}
public void draw_buf(Graphics g)
{
g.setColor(Color.blue);
for(int loop=0;loop<dot.size()-1;loop++)
{
Point p = (Point)dot.get(loop);
Point p1 = (Point)dot.get(loop + 1);
g.drawLine(p.x,p.y,p1.x,p1.y);
}
} public static void main(String[] args)
{
MainFrame win1=new MainFrame();
win1.setSize(600,600);
win1.show();
}
}//end of class MainFrame