/*
* TCSS 305 - Autumn 2012
* Homework 4: Power Paint
* Author: Levon Kechichian
*/
package powerpaint.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import powerpaint.tools.Tool;
/**
* The driver class that creates the PowerPaint program.
*
* @author Levon Kechichian
* @version Autumn 2012
*/
@SuppressWarnings("serial")
public class PowerPaintFrame extends JFrame
{
/**
* The text on the Color button.
*/
private static final String COLOR_BUTTON_TEXT = "Color...";
/**
* The number of thickness buttons.
*/
private static final int NUM_BUTTONS = 3;
/**
* The number of powerpaint tools.
*/
private static final int NUM_TOOLS = 4;
/**
* The grid item menu item.
*/
private final JCheckBoxMenuItem my_grid_item = new JCheckBoxMenuItem("Grid");
/**
* The "Extras" menu, from the menu bar.
*/
private JMenu my_extras_menu;
/**
* The "File" menu, from the menu bar.
*/
private JMenu my_file_menu;
/**
* The "Help" menu, from the menu bar.
*/
private JMenu my_help_menu;
/**
* The "Options" menu, from the menu bar.
*/
private JMenu my_options_menu;
/**
* The tool bar color button.
*/
private final JButton my_tool_bar_color = new JButton(COLOR_BUTTON_TEXT);
/**
* The "Tools" menu, from the menu bar.
*/
private JMenu my_tools_menu = new JMenu();
/**
* The toolbar for the tools.
*/
private final JToolBar my_tool_bar = new JToolBar();
/**
* The menu button group.
*/
private final ButtonGroup my_menu_group = new ButtonGroup();
/**
* The tool button group.
*/
private final ButtonGroup my_tool_group = new ButtonGroup();
/**
* The thickness button group.
*/
private final ButtonGroup my_thickness_group = new ButtonGroup();
/**
* The PowerPaint panel used for displaying "art".
*/
private final PowerPaintPanel my_paint_panel = new PowerPaintPanel();
/**
* Private constructor so that there are no derived classes.
*/
public PowerPaintFrame()
{
super("PowerPaint");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(my_paint_panel, BorderLayout.CENTER);
add(my_tool_bar, BorderLayout.SOUTH);
pack();
}
/**
* Method to create the menu bar safely.
*/
public void run()
{
setJMenuBar(createJMenuBar());
}
/**
* Method to create the Toolbar for the GUI.
*
* @return returns a toolbar with all the menu items.
*/
public JMenuBar createJMenuBar()
{
final JMenuBar powerpaint_bar = new JMenuBar();
createFileMenu();
powerpaint_bar.add(my_file_menu);
createOptionsMenu();
powerpaint_bar.add(my_options_menu);
createToolsMenu();
powerpaint_bar.add(my_tools_menu);
createHelpMenu();
powerpaint_bar.add(my_help_menu);
createExtrasMenu();
powerpaint_bar.add(my_extras_menu);
return powerpaint_bar;
}
/**
* Method to create the file menu and its items.
*/
public void createFileMenu()
{
my_file_menu = new JMenu("File");
my_file_menu.setMnemonic(KeyEvent.VK_F);
final JMenuItem clear = new JMenuItem("Clear", KeyEvent.VK_C);
clear.addActionListener(new ActionListener()
{
public void actionPerformed(final ActionEvent the_event)
{
my_paint_panel.getDrawnShapes().clear();
my_paint_panel.getCurrentTool().clear();
repaint();
}
});
my_file_menu.add(clear);
my_file_menu.addSeparator();
final JMenuItem quit = new JMenuItem("Quit", KeyEvent.VK_Q);
quit.addActionListener(new ActionListener()
{
public void actionPerformed(final ActionEvent the_event)
{
dispose();
}
});
my_file_menu.add(quit);
}
/**
* Method to create the options menu and its items.
*/
public void createOptionsMenu()
{
my_options_menu = new JMenu("Options");
my_options_menu.setMnemonic(KeyEvent.VK_O);
my_grid_item.addActionListener(new GridAction("Display a 2D grid",
KeyEvent.VK_G));
my_options_menu.add(my_grid_item);
final JMenu thickness = new JMenu("Thickness");
thickness.setMnemonic(KeyEvent.VK_T);
for (int i = 1; i < Math.pow(2.0, NUM_BUTTONS); i *= 2)
{
final String text = Integer.toString(i);
final JRadioButtonMenuItem button = new JRadioButtonMenuItem(text);
final ThicknessAction action = new ThicknessAction(button.getText(), i, button);
button.addActionListener(action);
my_thickness_group.add(button);
thickness.add(button);
}
my_options_menu.add(thickness);
}
/**
* Method to create the tools menu and its items.
*/
public void createToolsMenu()
{
my_tools_menu = new JMenu("Tools");
my_tools_menu.setMnemonic(KeyEvent.VK_T);
createColorButtons();
my_tools_menu.addSeparator();
for (int i = 0; i < NUM_TOOLS; i++)
{
final Tool paint_tool = my_paint_panel.getTools(i);
final JToggleButton tool_bar_button = new
JToggleButton(paint_tool.getToolName());
final JRadioButtonMenuItem menu_item_tool = new
JRadioButtonMenuItem(paint_tool.getToolName());
final ToolAction action = new ToolAction(paint_tool.getToolName(),
new ImageIcon(paint_tool.getIcon()), paint_tool.getToolTip(),
paint_tool.getMnemonic(),
my_paint_panel.getTools(i), tool_bar_button,
menu_item_tool);
menu_item_tool.setAction(action);
tool_bar_button.setAction(action);
if ("Pencil".equals(paint_tool.getToolName()))
{
tool_bar_button.setSelected(true);
menu_item_tool.setSelected(true);
my_paint_panel.setCurrentTool(paint_tool);
}
my_menu_group.add(menu_item_tool);
my_tools_menu.add(menu_item_tool);
my_tool_group.add(tool_bar_button);
my_tool_bar.add(tool_bar_button);
}
}
/**
* Method to create the Color buttons and attach
* their ColorAction listeners.
*
*/
public void createColorButtons()
{
final JMenuItem color_menu_item = new JMenuItem(COLOR_BUTTON_TEXT);
final ColorAction action = new ColorAction(COLOR_BUTTON_TEXT,
"Choose a color...", KeyEvent.VK_C);
color_menu_item.setAction(action);
my_tools_menu.add(color_menu_item);
my_paint_panel.setColor(Color.BLACK);
my_tool_bar_color.setBackground(Color.BLACK);
my_tool_bar_color.setAction(action);
my_tool_bar.add(my_tool_bar_color);
}
/**
* Method to create the help menu and its items.
*/
private void createHelpMenu()
{
my_help_menu = new JMenu("Help");
my_help_menu.setMnemonic(KeyEvent.VK_H);
final JMenuItem about = new JMenuItem("About...", KeyEvent.VK_A);
about.setToolTipText("View the about dialog");
about.addActionListener(new ActionListener()
{
public void actionPerformed(final ActionEvent the_event)
{
JOptionPane.showMessageDialog(null,
"TCSS 305 PowerPaint Special thanks to Dr.DMZ, v1.0");
}
});
my_help_menu.add(about);
}
/**
* Method to create the extra menu and its items.
*/
private void createExtrasMenu()
{
my_extras_menu = new JMenu("Extras");
my_extras_menu.setMnemonic(KeyEvent.VK_E);
final JMenuItem undo = new JMenuItem("Undo", KeyEvent.VK_U);
undo.setToolTipText("Undo the last drawing")
没有合适的资源?快使用搜索试试~ 我知道了~
Java-Paint-master.zip_java paint
共38个文件
class:19个
java:9个
xml:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 8 浏览量
2022-09-23
19:07:23
上传
评论
收藏 53KB ZIP 举报
温馨提示
simple paint project with java
资源详情
资源评论
资源推荐
收起资源包目录
Java-Paint-master.zip (38个子文件)
Java-Paint-master
pencil_bw.gif 879B
line_bw.gif 852B
bin
powerpaint
tools
Pencil.class 2KB
Rectangle.class 2KB
Tool.class 366B
Line.class 2KB
Ellipse.class 2KB
gui
PowerPaintFrame$ThicknessAction.class 1KB
DrawnShapes.class 909B
PowerPaintFrame$4.class 2KB
PowerPaintFrame$GridAction.class 1KB
PowerPaintFrame$5.class 2KB
PowerPaintPanel.class 5KB
PowerPaintFrame$2.class 760B
PowerPaintPanel$ToolListener.class 2KB
PowerPaintFrame$3.class 906B
PowerPaintFrame$1.class 1KB
PowerPaintFrame$ColorAction.class 2KB
PowerPaintFrame$ToolAction.class 2KB
PowerPaintFrame.class 7KB
Driver.class 1KB
ellipse_bw.gif 870B
support_files
tcss305_format_nextline.xml 28KB
tcss305_format_sameline.xml 28KB
tcss305_checkstyle_nextline_test.xml 13KB
tcss305_checkstyle_nextline.xml 13KB
tcss305_checkstyle_sameline.xml 13KB
tcss305_checkstyle_sameline_test.xml 13KB
rectangle_bw.gif 867B
src
Driver.java 1KB
powerpaint
tools
Ellipse.java 3KB
Pencil.java 3KB
Line.java 3KB
Rectangle.java 3KB
Tool.java 1KB
gui
PowerPaintPanel.java 7KB
PowerPaintFrame.java 15KB
DrawnShapes.java 2KB
共 38 条
- 1
钱亚锋
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0