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


// TODO add your handling code here:
if (start != null) {
end = evt.getPoint();
list.remove(current);
if (selectedShape == ShapeType.RECTANGLE) {
current = new Rectangle(start, end);
} else if (selectedShape == ShapeType.CIRCLE) {
current = new Circle(start, end);
}
if (current != null) {
list.add(current);
}
System.out.println(start + "," + end);
System.out.println("----");
repaint();
}
}
private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {
start = evt.getPoint();
end = evt.getPoint();
if (selectedShape == ShapeType.RECTANGLE) {
current = new Rectangle(start, end);
} else if (selectedShape == ShapeType.CIRCLE) {
current = new Circle(start, end);
}
if (current != null) {
list.add(current);
}
}
/**
* @param args
*the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Paint().setVisible(true);
}
});
}
enum ShapeType {
RECTANGLE, CIRCLE;
}
abstract class Shape {
abstract protected void paint(Graphics g);
}
class Rectangle extends Shape {
Point p1;
Point p2;
Rectangle(Point p1, Point p2) {
this.p1 = p1;
this.p2 = p2;
}
@Override
protected void paint(Graphics g) {
g.drawRect((int) p1.getX(), (int) p1.getY(), (int) (p2.getX() - p1
.getX()), (int) (p2.getY() - p1.getY()));
}
}
class Circle extends Shape {
Point p1;
Point p2;
Circle(Point p1, Point p2) {
this.p1 = p1;
this.p2 = p2;
}
@Override
protected void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
double x1 = p1.getX();
double y1 = p1.getY();
double x2 = p2.getX();
double y2 = p2.getY();
g2.drawOval((int) x1, (int) y1, (int) x2, (int) y2);
}
}
// Variables declaration - do not modify
private javax.swing.JLabel jlebel1;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
private Point start = null;
}
java语言写一个文本编辑器的源代码import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;//Date needed
import java.io.PrintWriter;
public class NotePad extends JFrame
{
JTextArea jta;
class newl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.setText("");
}
}
class openl implements ActionListener
{ public void actionPerformed(ActionEvent e)
{
JFileChooser jf=new JFileChooser();
jf.showOpenDialog(NotePad.this);
}
}
//保存文件的监听
class savel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser jf = new JFileChooser();
jf.showSaveDialog(NotePad.this);
}
}
//打印的监听 ?
class printl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// PrintWriter p = new PrintWriter(NotePad.this);
}
}
//退出记事本的监听
class exitl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);//退出
}
}
//拷贝的监听
class copyl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.copy();
}
}
//粘贴的监听
class pastel implements ActionListener
{
public void actionPerformed(ActionEvent e)

推荐阅读