⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menueventclass.java

📁 windows画图板.类似于windows自带的画图程序!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				}
			}
			ActionListener listener = new TimePrinter();
			Timer t = new Timer(1000, listener);
			t.start();
		} else if (e.getActionCommand().equals("旋转/翻转(F)...")) {

			about = new JDialog(new JFrame(), "旋转和翻转");
			about.setLayout(new BorderLayout());
			about.setIconImage(Toolkit.getDefaultToolkit().getImage(
					"E:\\java练习\\java练习\\SmallPhoto\\src\\img\\ICON.jpg"));
			JPanel setArea = new JPanel();
			Border border = BorderFactory.createEtchedBorder();
			Border borderTitle = BorderFactory.createTitledBorder(border,
					"旋转或翻转");
			setArea.setBorder(borderTitle);
			setArea.setLayout(new GridLayout(6, 1));

			ButtonGroup buttonGroup = new ButtonGroup();
			final JRadioButton level = new JRadioButton("水平翻转");
			level.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent f) {
					revolve = "水平翻转";
				}
			});
			level.setSelected(true);
			final JRadioButton perpendicular = new JRadioButton("垂直翻转");
			perpendicular.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent f) {
					revolve = "垂直翻转";
				}
			});
			final JRadioButton angleRevolve = new JRadioButton("按一定角度旋转");
			buttonGroup.add(level);
			setArea.add(level);
			buttonGroup.add(perpendicular);
			setArea.add(perpendicular);
			buttonGroup.add(angleRevolve);
			setArea.add(angleRevolve);

			ButtonGroup angleRevolveGP = new ButtonGroup();
			final JRadioButton angle90 = new JRadioButton("90度");
			angle90.setEnabled(false);
			angle90.setSelected(true);
			angle90.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent f) {
					revolve = "90度";
				}
			});
			final JRadioButton angle180 = new JRadioButton("180度");
			angle180.setEnabled(false);
			angle180.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent f) {
					revolve = "180度";
				}
			});
			final JRadioButton angle270 = new JRadioButton("270度");
			angle270.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent f) {
					revolve = "270度";
				}
			});
			angle270.setEnabled(false);
			level.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					angle90.setEnabled(false);
					angle180.setEnabled(false);
					angle270.setEnabled(false);
				}
			});
			perpendicular.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					angle90.setEnabled(false);
					angle180.setEnabled(false);
					angle270.setEnabled(false);
				}
			});
			angleRevolve.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					angle90.setEnabled(true);
					angle180.setEnabled(true);
					angle270.setEnabled(true);
				}
			});
			angleRevolveGP.add(angle90);
			setArea.add(angle90);
			angleRevolveGP.add(angle180);
			setArea.add(angle180);
			angleRevolveGP.add(angle270);
			setArea.add(angle270);
			JPanel buttonArea = new JPanel();
			buttonArea.setLayout(new GridLayout(5, 1));
			JButton sure = new JButton("确定");
			JButton cancel = new JButton("取消");
			cancel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					about.setVisible(false);
				}
			});
			buttonArea.add(new JLabel(""));
			buttonArea.add(sure);
			buttonArea.add(new JLabel(""));
			buttonArea.add(cancel);
			buttonArea.add(new JLabel(""));
			about.add(setArea, BorderLayout.CENTER);
			about.add(buttonArea, BorderLayout.EAST);
			about.setSize(250, 200);
			about.setVisible(true);
			about.setResizable(false);
			sure.addActionListener(new ImageProcess());
		} else if (e.getActionCommand().equals("拉伸/扭曲(S)...")) {

			final JDialog pullAndStretch = new JDialog(new JFrame(), "拉伸和扭曲");
			pullAndStretch.setLayout(new BorderLayout());
			pullAndStretch.setIconImage(Toolkit.getDefaultToolkit().getImage(
					"E:\\java练习\\java练习\\SmallPhoto\\src\\img\\ICON.jpg"));
			JPanel left = new JPanel();
			left.setLayout(new GridLayout(2, 1));
			JPanel pull = new JPanel();
			Border border = BorderFactory.createEtchedBorder();
			Border borderTitle = BorderFactory.createTitledBorder(border, "拉伸");
			pull.setBorder(borderTitle);
			pull.setLayout(new GridLayout(2, 3));
			JLabel level = new JLabel("水平:");
			JLabel perpendicula = new JLabel("垂直:");
			final JTextField levelText = new JTextField();
			levelText.addFocusListener(new FocusListener() {
				public void focusGained(FocusEvent e) {

				}

				public void focusLost(FocusEvent arg0) {

					shuiPingLaShen = Float.parseFloat(levelText.getText()) / 100;
				}
			});
			final JTextField perpendiculaText = new JTextField();
			perpendiculaText.addFocusListener(new FocusListener() {
				public void focusGained(FocusEvent e) {

				}

				public void focusLost(FocusEvent arg0) {
					chuiZiLaShen = Float.parseFloat(perpendiculaText.getText()) / 100;

				}
			});
			JLabel levelLabel = new JLabel("  %");
			JLabel perpendiculaLabel = new JLabel("  %");
			pull.add(level);
			pull.add(levelText);
			pull.add(levelLabel);
			pull.add(perpendicula);
			pull.add(perpendiculaText);
			pull.add(perpendiculaLabel);

			JPanel stretch = new JPanel();
			Border borderStretch = BorderFactory.createEtchedBorder();
			Border borderTitleStretch = BorderFactory.createTitledBorder(
					borderStretch, "扭曲");
			stretch.setBorder(borderTitleStretch);
			stretch.setLayout(new GridLayout(2, 3));
			JLabel stretchLevel = new JLabel("水平:");
			JLabel stretchPerpendicula = new JLabel("垂直:");
			final JTextField stretchLevelText = new JTextField();
			stretchLevelText.addFocusListener(new FocusListener() {
				public void focusGained(FocusEvent e) {

				}

				public void focusLost(FocusEvent arg0) {

					shuiPingNiuQu = Float
							.parseFloat(stretchLevelText.getText());
				}
			});
			final JTextField stretchPerpendiculaText = new JTextField();
			stretchPerpendiculaText.addFocusListener(new FocusListener() {
				public void focusGained(FocusEvent e) {

				}

				public void focusLost(FocusEvent arg0) {

					chuiZiNiuQu = Float.parseFloat(stretchPerpendiculaText
							.getText());
				}
			});
			JLabel stretchLevelLabel = new JLabel("  度");
			JLabel stretchPerpendiculaLabel = new JLabel("  度");
			stretch.add(stretchLevel);
			stretch.add(stretchLevelText);
			stretch.add(stretchLevelLabel);
			stretch.add(stretchPerpendicula);
			stretch.add(stretchPerpendiculaText);
			stretch.add(stretchPerpendiculaLabel);

			left.add(pull);
			left.add(stretch);

			JPanel buttonArea = new JPanel();
			buttonArea.setLayout(new GridLayout(5, 1));
			JButton sure = new JButton("确定");
			sure.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					pullAndStretch.setVisible(false);
					ImageProcess img = new ImageProcess();
					img.niuQu(shuiPingNiuQu, chuiZiNiuQu);
					for (int i = 0; i <= 1000; i++) {

					}
					laShen(DrawingBoard.picture, shuiPingLaShen, chuiZiLaShen);
				}
			});
			JButton cancel = new JButton("取消");
			cancel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					pullAndStretch.setVisible(false);
				}
			});
			buttonArea.add(new JLabel(""));
			buttonArea.add(sure);
			buttonArea.add(new JLabel(""));
			buttonArea.add(cancel);
			buttonArea.add(new JLabel(""));

			pullAndStretch.setSize(220, 200);
			pullAndStretch.setVisible(true);
			pullAndStretch.add(left, BorderLayout.CENTER);
			pullAndStretch.add(buttonArea, BorderLayout.EAST);
			pullAndStretch.setResizable(false);
		} else if (e.getActionCommand().equals("属性(A)...")) {

			final JDialog Attribute = new JDialog(new JFrame(), "属性");
			Attribute.setLayout(new BorderLayout());
			Attribute.setIconImage(Toolkit.getDefaultToolkit().getImage(
					"E:\\java练习\\java练习\\SmallPhoto\\src\\img\\ICON.jpg"));
			JPanel left = new JPanel();
			left.setLayout(new GridLayout(4, 1));

			JPanel infoPane = new JPanel();
			infoPane.setLayout(new GridLayout(3, 1));
			JLabel saveTime = new JLabel("上次保存的时间:");
			JLabel saveInfo = new JLabel();
			JLabel fileSize = new JLabel("磁盘大小:");
			JLabel fileInfo = new JLabel();
			JLabel Resolution = new JLabel("分辨率:");
			Integer imgWidthPiexl = DrawingBoard.picture.getWidth(null);
			Integer imgHeightPiexl = DrawingBoard.picture.getHeight(null);
			JLabel ResolutionInfo = new JLabel(imgWidthPiexl.toString() + "*"
					+ imgHeightPiexl.toString());

			infoPane.add(saveTime);
			infoPane.add(saveInfo);
			infoPane.add(fileSize);
			infoPane.add(fileInfo);
			infoPane.add(Resolution);
			infoPane.add(ResolutionInfo);
			if (imgFile == null) {
				saveInfo.setText("不可用");
				fileInfo.setText("不可用");
			} else {
				Long lastAccess = imgFile.lastModified();
				Long imgSize = imgFile.length();
				saveInfo.setText(lastAccess.toString());
				fileInfo.setText(imgSize.toString() + "  个字节");
			}
			JPanel widthHeight = new JPanel();
			widthHeight.setLayout(new GridLayout(1, 4));
			JLabel width = new JLabel("宽度:");
			final Integer imgWidth = DrawingBoard.picture.getWidth(null);
			final JTextField widthInfo = new JTextField(imgWidth);
			widthInfo.setText(imgWidth.toString());
			JLabel height = new JLabel("高度:");
			final JTextField heightInfo = new JTextField();
			final Integer imgHeight = DrawingBoard.picture.getHeight(null);
			heightInfo.setText(imgHeight.toString());
			widthHeight.add(width);
			widthHeight.add(widthInfo);
			widthHeight.add(height);
			widthHeight.add(heightInfo);

			JPanel Unit = new JPanel();
			Border border = BorderFactory.createEtchedBorder();
			Border borderTitle = BorderFactory.createTitledBorder(border, "单位");
			Unit.setBorder(borderTitle);
			Unit.setLayout(new GridLayout(1, 3));
			ButtonGroup buttonGroup = new ButtonGroup();
			JRadioButton inch = new JRadioButton("英寸");
			JRadioButton LiRice = new JRadioButton("厘米");
			final JRadioButton pixel = new JRadioButton("像数");
			pixel.setSelected(true);
			buttonGroup.add(inch);
			Unit.add(inch);
			buttonGroup.add(LiRice);
			Unit.add(LiRice);
			buttonGroup.add(pixel);
			Unit.add(pixel);
			pixel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					widthInfo.setText(imgWidth.toString());
					heightInfo.setText(imgHeight.toString());
				}
			});
			LiRice.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					Integer width = imgWidth / 38;
					Integer height = imgHeight / 38;
					widthInfo.setText(width.toString());
					heightInfo.setText(height.toString());
				}
			});
			inch.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					Integer width = imgWidth / 96;
					Integer height = imgHeight / 96;
					widthInfo.setText(width.toString());
					heightInfo.setText(height.toString());
				}
			});
			JPanel color = new JPanel();
			Border colorBorder = BorderFactory.createEtchedBorder();
			Border colorBorderTitle = BorderFactory.createTitledBorder(
					colorBorder, "颜色");
			color.setBorder(colorBorderTitle);
			color.setLayout(new GridLayout(1, 2));
			ButtonGroup colorButtonGroup = new ButtonGroup();
			final JRadioButton blackWhite = new JRadioButton("黑白");
			final JRadioButton colorBlik = new JRadioButton("彩色");
			colorBlik.setSelected(true);
			color.add(blackWhite);
			colorButtonGroup.add(blackWhite);
			color.add(colorBlik);
			colorButtonGroup.add(colorBlik);

			left.add(infoPane);
			left.add(widthHeight);
			left.add(Unit);
			left.add(color);

			JPanel buttonArea = new JPanel();
			buttonArea.setLayout(new GridLayout(7, 1));
			JButton sure = new JButton("确定");
			JButton cancel = new JButton("取消");
			buttonArea.add(new JLabel(""));
			buttonArea.add(sure);
			buttonArea.add(new JLabel(""));
			buttonArea.add(new JLabel(""));
			buttonArea.add(cancel);
			cancel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					Attribute.setVisible(false);
				}
			});
			sure.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (blackWhite.isSelected()) {
						Attribute.setVisible(false);
						new ImageProcess().gray();
					} else {
						try {
							Attribute.setVisible(false);
							DrawingBoard.picture = ImageIO
									.read(MenuEventClass.imgFile);
							Graphics g = null;
							Panel.drawCanvas.paintComponent(g);
						} catch (IOException f) {
							f.printStackTrace();
						}
					}
				}
			});
			Attribute.setSize(320, 230);
			Attribute.setVisible(true);
			Attribute.add(left, BorderLayout.CENTER);
			Attribute.add(buttonArea, BorderLayout.EAST);
			Attribute.setResizable(false);
		} else if (e.getActionCommand().equals("自定义(U)...")) {

			final JDialog defineSelf = new JDialog(new JFrame(), "自定义缩放");
			defineSelf.setLayout(new BorderLayout());
			defineSelf.setIconImage(Toolkit.getDefaultToolkit().getImage(
					"E:\\java练习\\java练习\\SmallPhoto\\src\\img\\ICON.jpg"));

			final JPanel left = new JPanel();
			left.setLayout(new GridLayout(2, 1));

			JPanel scale = new JPanel();
			scale.setLayout(new GridLayout(1, 2));
			JLabel comparison = new JLabel("当前缩放比例:");
			final JLabel comparisonInfo = new JLabel("100%");
			scale.add(comparison);
			scale.add(comparisonInfo);

			JPanel scaleComparison = new JPanel();
			Border border = BorderFactory.createEtchedBorder();
			Border borderTitle = BorderFactory
					.createTitledBorder(border, "缩放到");
			scaleComparison.setBorder(borderTitle);
			scaleComparison.setLayout(new GridLayout(2, 3));

			ButtonGroup buttonGroup = new ButtonGroup();
			final JRadioButton scale100 = new JRadioButton("100%");
			scale100.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					comparisonInfo.setText("100%");
				}
			});
			final JRadioButton scale200 = new JRadioButton("200%");
			scale200.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					comparisonInfo.setText("200%");
				}
			});
			final JRadioButton scale400 = new JRadioButton("400%");
			scale400.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					comparisonInfo.setText("400%");
				}
			});
			final JRadioButton scale600 = new JRadioButton("600%");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -