java简单编辑器代码 java简单编辑器代码怎么写( 三 )


menubar.add(menu_size);
menuitem_20=new JMenuItem("20");
menu_size.add(menuitem_20);
menuitem_20.addActionListener(this);
menuitem_30=new JMenuItem("30");
menu_size.add(menuitem_30);
menuitem_30.addActionListener(this);
menuitem_40=new JMenuItem("40");
menu_size.add(menuitem_40);
menuitem_40.addActionListener(this);
popupmenu=new JPopupMenu();//快捷菜单
JMenuItem menuitem_red=new JMenuItem("红色");
popupmenu.add(menuitem_red);
menuitem_red.addActionListener(this);
JMenuItem menuitem_green=new JMenuItem("绿色");
popupmenu.add(menuitem_green);
menuitem_green.addActionListener(this);
menuitem_blue=new JMenuItem("蓝色");
popupmenu.add(menuitem_blue);
menuitem_blue.addActionListener(this);
textarea.add(popupmenu);//向文本区内添加快捷菜单
}
public void writeToFile(String lines)//写文件
{
try
{
FileWriter fout = new FileWriter(this.file);
fout.write(lines+"\r\n");
fout.close();
}
catch (IOException ioex)
{
return;
}
}
public String readFromFile()//读文件
{
try
{
FileReader fin = new FileReader(this.file);
BufferedReader bin = new BufferedReader(fin);
String aline="", lines="";
do
{
aline = bin.readLine();
if (aline!=null)
lines += aline + "\r\n";
} while (aline!=null);
bin.close();
fin.close();
return lines;
}
catch (IOException ioex)
{
return null;
}
}
急需!!基于java的图形编辑器源代码本来不该直接给人作业java简单编辑器代码的java简单编辑器代码,所以一些格式很乱也不打算改java简单编辑器代码了 。框架已经写好java简单编辑器代码,自己参考着加上三角形java简单编辑器代码的功能吧(总得自己做点东西吧) 。
/*
* Paint.java
*
* Created on May 9, 2008, 10:10 AM
*/
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author uestcfb
*/
public class Paint extends JFrame {
ListShape list = new ArrayListShape();
private Point end;
class PaintArea extends JPanel {
ListShape list;
public PaintArea(ListShape list) {
this.list = list;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for (Shape s : list) {
s.paint(g);
}
}
}
private ShapeType selectedShape = ShapeType.values()[0];
/** Creates new form Paint */
public Paint() {
initComponents();
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// editor-fold defaultstate="collapsed" desc="Generated Code"
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox(ShapeType.values());
jPanel1 = new PaintArea(list);
jlebel1 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jPanel1MousePressed(evt);

推荐阅读