Иллюстрированный самоучитель по Java


              

public Dimension


c.add(black); с.addSeparator(); с.add(clear);

red.addActionListener(this); 

green.addActionListener(this); 

blue.addActionListener(this); 

black.addActionListener(this); 

clear.addActionListener(this); 



public Dimension getPreferredSize()

{

return new Dimension(w, h); 

}

public void actionPerformed(ActionEvent event){

String s = event.getActionCommand();

if (s.equals("Очистить")) repaint();

else if (s.equals("Красный")) currColor = Color.red;

else if (s.equals("Зеленый")) currColor = Color.green;

else if (s.equals("Синий")) currColor = Color.blue;

else if (s.equals("Черный")) currColor = Color.black; 

}

public void processMouseEvent(MouseEvent e){ 

if (e.isPopupTrigger())

c.show(e.getComponent (), e.getXO, e.getY()); 

else if (e.getlDO == MouseEvent.MOUSE_PRESSED){

lastX = e.getX(); lastY = e.getY(); }

else super.processMouseEvent(e); }

public void processMouseMotionEvent(MouseEvent e){ 

if (e.getlDO = MouseEvent.MOUSE_DRAGGED){ 

Graphics g = getGraphics();

g.setColor(currColor) ;

g.drawLinedastX, lastY, e.getX(), e.getY()); 

lastX = e.getX(); lastY = e.getY(); 

}

else super.processMouseMotionEvent(e); 



}





Рис. 13.3.


Программа рисования  с всплывающим меню


Содержание  Назад