هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.


 
الرئيسيةجستجوأحدث الصورثبت نامورود

 

 کار با قلم نو.ري

اذهب الى الأسفل 
3 مشترك
نويسندهپيام
saleh120




تعداد پستها : 41
Age : 39
Location : اصفهان
Registration date : 2008-03-13

کار با قلم نو.ري Empty
پستعنوان: کار با قلم نو.ري   کار با قلم نو.ري Icon_minitimeالأربعاء نوفمبر 12, 2008 10:45 am

سلام دوستان
می خواستم بدونم چطوری ما می توانیم برای قلم نوری برنامه بنویسیم مثلا در محیط Canvas کاری کنیم که قلم خط بکشد در اصل می خواهم event های down و up و ... را هندل کنم؟ confused
بازگشت به بالاي صفحه اذهب الى الأسفل
vvampirevv




تعداد پستها : 19
Registration date : 2008-10-30

کار با قلم نو.ري Empty
پستعنوان: رد: کار با قلم نو.ري   کار با قلم نو.ري Icon_minitimeالأربعاء نوفمبر 12, 2008 11:51 pm

یک مثال خیلی ساده که با قلم روی صفحه نقاشی می کنه
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Doodle extends MIDlet
{
private Display display; // The display
private DoodleCanvas canvas; // Canvas

public Doodle()
{
display = Display.getDisplay(this);
canvas = new DoodleCanvas(this);
}

protected void startApp()
{
display.setCurrent( canvas );
}

protected void pauseApp()
{ }

protected void destroyApp( boolean unconditional )
{ }

public void exitMIDlet()
{
destroyApp(true);
notifyDestroyed();
}
}

/*--------------------------------------------------
* Class DoodleCanvas
*
* Pointer event handling
*-------------------------------------------------*/
class DoodleCanvas extends Canvas implements CommandListener
{
private Command cmExit; // Exit midlet

private Command cmClear; // Clear display

private int startx = 0, // Where pointer was clicked

starty = 0,

currentx = 0, // Current location

currenty = 0;
private Doodle midlet;
private boolean clearDisplay = false;

/*--------------------------------------------------
* Constructor
*-------------------------------------------------*/
public DoodleCanvas(Doodle midlet)
{
this.midlet = midlet;

// Create exit command & listen for events
cmExit = new Command("Exit", Command.EXIT, 1);
cmClear = new Command("Clear", Command.SCREEN, 1);
addCommand(cmExit);
addCommand(cmClear);
setCommandListener(this);
}

/*--------------------------------------------------
* Paint the text representing the key code
*-------------------------------------------------*/
protected void paint(Graphics g)
{
// Clear the background (to white)
if (clearDisplay)
{
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());

clearDisplay = false;
startx = currentx = starty = currenty = 0;

return;
}

// Draw with black pen
g.setColor(0, 0, 0);

// Draw line
g.drawLine(startx, starty, currentx, currenty);

// New starting point is the current position
startx = currentx;
starty = currenty;
}

/*--------------------------------------------------
* Command event handling
*-------------------------------------------------*/
public void commandAction(Command c, Displayable d)
{
if (c == cmExit)
midlet.exitMIDlet();
else if (c == cmClear)
{
clearDisplay = true;
repaint();
}
}

/*--------------------------------------------------
* Pointer pressed
*-------------------------------------------------*/
protected void pointerPressed(int x, int y)
{
startx = x;
starty = y;
}

/*--------------------------------------------------
* Pointer moved
*-------------------------------------------------*/
protected void pointerDragged(int x, int y)
{
currentx = x;
currenty = y;
repaint();
}
}
saleh120 نوشته است:
سلام دوستان
می خواستم بدونم چطوری ما می توانیم برای قلم نوری برنامه بنویسیم مثلا در محیط Canvas کاری کنیم که قلم خط بکشد در اصل می خواهم event های down و up و ... را هندل کنم؟ confused
بازگشت به بالاي صفحه اذهب الى الأسفل
Admin
Admin
Admin


تعداد پستها : 455
Location : Linux
Registration date : 2007-08-28

کار با قلم نو.ري Empty
پستعنوان: پاسخ   کار با قلم نو.ري Icon_minitimeالجمعة نوفمبر 21, 2008 2:43 am

ممنونم
بازگشت به بالاي صفحه اذهب الى الأسفل
http://j2me.blogfa.com
 
کار با قلم نو.ري
بازگشت به بالاي صفحه 
صفحه 1 از 1

صلاحيات هذا المنتدى:شما نمي توانيد در اين بخش به موضوعها پاسخ دهيد
 :: سوال و جواب-
پرش به: