Skip to content

Commit

Permalink
修复乱码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
shensr-s committed Oct 5, 2019
1 parent 6e0a23a commit ae380d1
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 90 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@



定义一个Text类,继承Shape类,用于文字输入
2 changes: 1 addition & 1 deletion paint/src/cn/edu/nwafu/shape/Brush.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Random;

/**
* ����
* 刷子类
* @author Administrator
*
*/
Expand Down
2 changes: 0 additions & 2 deletions paint/src/cn/edu/nwafu/shape/Images.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.awt.*;

public class Images extends Shape{




public void draw(Graphics2D g) {
Expand Down
4 changes: 2 additions & 2 deletions paint/src/cn/edu/nwafu/shape/Pencil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public Pencil(){
}
public void draw(Graphics2D g) {
g.setPaint(color);
//Ϊ Graphics2D ���������� Stroke

g.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
//Ϊ�����㷨���õ�����ѡ���ֵ��

g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

g.drawLine(x1, y1, x2, y2);
Expand Down
2 changes: 1 addition & 1 deletion paint/src/cn/edu/nwafu/shape/Rubber.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* 橡皮檫类
* @author 沈仕瑞
* @author
*
*/
public class Rubber extends Shape {
Expand Down
31 changes: 15 additions & 16 deletions paint/src/cn/edu/nwafu/shape/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

import java.awt.*;

public class Text extends Shape// 文字
{

/**
* 定义一个Text类,继承Shape类,用于文字输入
*
*/
public class Text extends Shape {

public void draw(Graphics2D g) {
//Font(String name, int style, int size)
g.setColor(color);
g.setFont(new Font(fontName, italic+blodtype, fontSize));
if (s != null) {

g.drawString(s, x1, y1);
//System.out.println(fontName+" "+s+" "+fontSize );
}
}
/**
* 定义一个Text类,继承Shape类,用于文字输入
*/

public void draw(Graphics2D g) {
//Font(String name, int style, int size)
g.setColor(color);
g.setFont(new Font(fontName, italic + blodtype, fontSize));
if (s != null) {

g.drawString(s, x1, y1);
//System.out.println(fontName+" "+s+" "+fontSize );
}
}
}
42 changes: 14 additions & 28 deletions paint/src/cn/edu/nwafu/start/MyFrame.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
package cn.edu.nwafu.start;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import cn.edu.nwafu.shape.Rectangle;
import cn.edu.nwafu.shape.Shape;
import cn.edu.nwafu.shape.*;
import cn.edu.nwafu.tools.ColorPanel;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;

import cn.edu.nwafu.shape.Circle;
import cn.edu.nwafu.shape.Hexagon;
import cn.edu.nwafu.shape.Images;
import cn.edu.nwafu.shape.Line;
import cn.edu.nwafu.shape.Oval;
import cn.edu.nwafu.shape.Brush;
import cn.edu.nwafu.shape.Pencil;
import cn.edu.nwafu.shape.Pentagon;
import cn.edu.nwafu.shape.Rectangle;
import cn.edu.nwafu.shape.RoundRect;
import cn.edu.nwafu.shape.Rubber;
import cn.edu.nwafu.shape.Shape;
import cn.edu.nwafu.shape.Text;
import cn.edu.nwafu.shape.Triangle;
import cn.edu.nwafu.shape.FillCircle;
import cn.edu.nwafu.shape.FillOval;
import cn.edu.nwafu.shape.FillRect;
import cn.edu.nwafu.shape.FillRoundRect;
import cn.edu.nwafu.tools.ColorPanel;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class MyFrame extends JFrame {

Expand Down Expand Up @@ -761,12 +746,13 @@ public void addToorbar() {

toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
toolbar.setBackground(new Color(195, 195, 195));
btn_blod = new Checkbox("粗体");
btn_italic = new Checkbox("斜体");
//中文会乱码
btn_blod = new Checkbox("blod");//粗体
btn_italic = new Checkbox("italic");//斜体
btn_blod.setBackground(new Color(195, 195, 195));
btn_italic.setBackground(new Color(195, 195, 195));
btn_blod.setPreferredSize(new Dimension(40, 30));
btn_italic.setPreferredSize(new Dimension(40, 30));
btn_blod.setPreferredSize(new Dimension(45, 30));
btn_italic.setPreferredSize(new Dimension(45, 30));

jfont_size = new JComboBox<String>(fontSize);
jfont_size.setPreferredSize(new Dimension(50, 30));
Expand Down
2 changes: 0 additions & 2 deletions paint/src/cn/edu/nwafu/start/StartProject.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cn.edu.nwafu.start;

import javax.swing.UIManager;

public class StartProject {
/**
* 启动界面
Expand Down
66 changes: 28 additions & 38 deletions paint/src/cn/edu/nwafu/tools/ColorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

public class ColorPanel extends JPanel {

/**
*
*/
private static final long serialVersionUID = 1L;
// 左边面板添加子面板
private JPanel paneldownchild;
Expand All @@ -34,13 +31,13 @@ public class ColorPanel extends JPanel {
private ImageIcon iconn;
// 调色板
// 颜色数组,用来设置按钮的背景颜色
private Color[] colors = { new Color(255, 255, 255), new Color(0, 0, 0), new Color(127, 127, 127),
private Color[] colors = {new Color(255, 255, 255), new Color(0, 0, 0), new Color(127, 127, 127),
new Color(195, 195, 195), new Color(136, 0, 21), new Color(185, 122, 87), new Color(237, 28, 36),
new Color(255, 174, 201), new Color(255, 127, 39), new Color(255, 242, 0), new Color(239, 228, 176),
new Color(34, 117, 76), new Color(181, 230, 29), new Color(0, 162, 232), new Color(153, 217, 234),
new Color(63, 72, 204), new Color(112, 146, 190), new Color(163, 73, 164), new Color(200, 191, 231),
new Color(89, 173, 154), new Color(8, 193, 194), new Color(9, 253, 76), new Color(153,217,234),
new Color(199, 73, 4) };
new Color(89, 173, 154), new Color(8, 193, 194), new Color(9, 253, 76), new Color(153, 217, 234),
new Color(199, 73, 4)};

public ColorPanel() {
addColorPanel();
Expand Down Expand Up @@ -127,42 +124,35 @@ public void actionPerformed(ActionEvent e) {
btn_color.setPreferredSize(new Dimension(40, 40));
btn_color.setToolTipText("更多颜色");
right.add(btn_color);
btn_color.addActionListener(new ActionListener() {
btn_color.addActionListener(e -> chooseColor());//java8的lambda表达式,和下边注释代码功能相同
// btn_color.addActionListener(new ActionListener() {
//
// @Override
// public void actionPerformed(ActionEvent e) {
// chooseColor();
//
// }
// });
//java8的lambda表达式,
bt.addActionListener(e -> {
// 拿到被选中按钮的对象
JButton jbt = (JButton) e.getSource();
// 拿到被选中按钮的背景颜色
Color c = jbt.getBackground();
// 把背景颜色复制给WIndowStart中的颜色属性
MyFrame.color = c;
MyFrame.itemList[MyFrame.index].color = c;

@Override
public void actionPerformed(ActionEvent e) {
chooseColor();

}
});

bt.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// 拿到被选中按钮的对象
JButton jbt = (JButton) e.getSource();
// 拿到被选中按钮的背景颜色
Color c = jbt.getBackground();
// 把背景颜色复制给WIndowStart中的颜色属性
MyFrame.color = c;
MyFrame.itemList[MyFrame.index].color = c;

}
});

bt1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// 拿到被选中按钮的对象
JButton jbt = (JButton) e.getSource();
// 拿到被选中按钮的背景颜色
Color c = jbt.getBackground();
MyFrame.color = c;
MyFrame.itemList[MyFrame.index].color = c;
bt1.addActionListener(e -> {
// 拿到被选中按钮的对象
JButton jbt = (JButton) e.getSource();
// 拿到被选中按钮的背景颜色
Color c = jbt.getBackground();
MyFrame.color = c;
MyFrame.itemList[MyFrame.index].color = c;

}
});

}
Expand Down

0 comments on commit ae380d1

Please sign in to comment.