WallPaper
Описание и работа:
Программа, позволяющая предворительно посмотреть арнамент. Просто нарисуйте что-нибудь в первом (слева) квадрате, и посмотрите, что из этого выйдет.(Если никак не хочет рисовать, то измените цвет на какой-либо другой, не черный.) Также Вы можете постройть линию по 4-ем координатам.(мин x=0, мин y=0, макс x=293, макс y=300)
Download:     [WallPaper.class]


Программа:

import java.applet.*; import java.awt.*; public class risovalka extends Applet { private int last_x, last_y; // Store the last mouse position. private Color current_color = Color.black; // Store the current color. private Button clear_button; // The clear button. private TextField root_1, root_2, root_3, root_4; private Button button; private Choice color_choices; // The color dropdown list. int a,b,c,d; public void init() { setLayout( new FlowLayout(FlowLayout.LEFT, 2, 2 )); this.setBackground(Color.lightGray); clear_button = new Button("Clear"); clear_button.setForeground(Color.black); clear_button.setBackground(Color.red); this.add(new Label(" ")); this.add(clear_button); root_1 = new TextField("x1", 1); root_1.setForeground(Color.black); root_1.setBackground(Color.yellow); root_2 = new TextField("y1", 1); root_2.setForeground(Color.black); root_2.setBackground(Color.green); root_3 = new TextField("x2", 1); root_3.setForeground(Color.black); root_3.setBackground(Color.yellow); root_4 = new TextField("y2", 1); root_4.setForeground(Color.black); root_4.setBackground(Color.green); // this.add(new Label("X :")); this.add(root_1); this.add(root_2); this.add(root_3); this.add(root_4); button = new Button("Line"); button.setForeground(Color.black); button.setBackground(Color.white); this.add(button); color_choices = new Choice(); color_choices.addItem("black"); color_choices.addItem("white"); color_choices.addItem("red"); color_choices.addItem("yellow"); color_choices.addItem("green"); color_choices.setForeground(Color.black); color_choices.setBackground(Color.lightGray); this.add(color_choices); } // This method is called when the user clicks the mouse to start a scribble. public boolean mouseDown(Event e, int x, int y) { last_x = x; last_y = y; return true; } public void paint(Graphics g) { g.setColor(Color.lightGray); g.fillRect(0 , 0, 500, 30); g.setColor(Color.black); g.fillRect(0 , 30, 300, 330); g.fillRect(300 , 130, 500, 330); g.setColor(Color.white); g.drawLine(300 , 130, 300, 330); g.drawLine(300 , 130, 500, 130); g.setColor(Color.black); g.drawLine(300 , 180, 500, 180); g.drawLine(300 , 230, 500, 230); g.drawLine(300 , 280, 500, 280); // g.drawLine(350 , 130, 350, 330); g.drawLine(400 , 130, 400, 330); g.drawLine(450 , 130, 450, 330); } // This method is called when the user drags the mouse. public boolean mouseDrag(Event e, int x, int y) { Graphics g = this.getGraphics(); g.setColor(current_color); if (last_y > 30 && last_x < 300) { g.drawLine(x, y, last_x, last_y); } for(int l = 300; l<=450; l = l+50) { for(int m = 300; m<=500; m = m+50) { if ((x/6 + m) > m && last_x/6 + m < m+50 && (y/6 + m - 175) > (m - 175) && (last_y/6 + m - 175) < (m - 125)) { g.drawLine(x/6 + l, y/6 + m - 175, last_x/6 + l, last_y/6 + m - 175); } } } last_x = x; last_y = y; return true; } public boolean action(Event event, Object arg) { if (event.target == color_choices) { if (arg.equals("black")) current_color = Color.black; else if (arg.equals("white")) current_color = Color.white; else if (arg.equals("red")) current_color = Color.red; else if (arg.equals("yellow")) current_color = Color.yellow; else if (arg.equals("green")) current_color = Color.green; return true; } if (event.target == button) { Graphics g = this.getGraphics(); try { a=Integer.parseInt(root_1.getText()); b=Integer.parseInt(root_2.getText()); c=Integer.parseInt(root_3.getText()); d=Integer.parseInt(root_4.getText()); } catch(NumberFormatException e) { root_1.setText(""); root_2.setText(""); root_3.setText(""); root_4.setText(""); } g.setColor(current_color); int x = a+6; int y = b+30; int last_x = c+6; int last_y = d+30; if (last_y > 30 && last_x < 300) { g.drawLine(x, y, last_x, last_y); } for(int l = 300; l<=450; l = l+50) { for(int m = 300; m<=500; m = m+50) { if ((x/6 + m) > m && last_x/6 + m < m+50 && (y/6 + m - 175) > (m - 175) && (last_y/6 + m - 175) < (m - 125)) { g.drawLine(x/6 + l, y/6 + m - 175, last_x/6 + l, last_y/6 + m - 175); } } } } if (event.target == clear_button) { Graphics g = this.getGraphics(); g.setColor(Color.lightGray); g.fillRect(0 , 0, 500, 30); g.fillRect(300 , 30, 500, 130); g.setColor(Color.black); g.fillRect(0 , 30, 300, 330); g.fillRect(300 , 130, 500, 330); g.setColor(Color.white); g.drawLine(300 , 130, 300, 330); g.drawLine(300 , 130, 500, 130); g.setColor(Color.black); g.drawLine(300 , 180, 500, 180); g.drawLine(300 , 230, 500, 230); g.drawLine(300 , 280, 500, 280); // g.drawLine(350 , 130, 350, 330); g.drawLine(400 , 130, 400, 330); g.drawLine(450 , 130, 450, 330); return true; } // Otherwise, let the superclass handle it. else return super.action(event, arg); } }

Aport Ranker be number one


Копейка не несет никакой ответственности за предоставленные материалы.
Copyright © 1999 Копейка.

Сайт создан в системе uCoz