Java / 10
.docМіністерство освіти і науки України
ДЕРЖАВНИЙ ВИЩИЙ НАВЧАЛЬНИЙ ЗАКЛАД
«НАЦІОНАЛЬНИЙ ГІРНИЧИЙ УНІВЕРСИТЕТ»
ІНСТИТУТ ЕЛЕКТРОЕНЕРГЕТИКИ
ФАКУЛЬТЕТ ІНФОРМАЦІЙНИХ ТЕХНОЛОГІЙ
Кафедра програмного забезпечення комп'ютерних систем
ЗВІТ
З ЛАБОРАТОРНОЇ РОБОТИ № 10
з дисципліни “Мережеве Java програмування”
-
Виконав:
ст. гр. КНіт-10-1
Левченко О. А.
Перевірив:
Зінченко О. В.
Харь О. Т.
Дніпропетровськ
2014
Лабораторная работа №10
Разработка мобильных приложений
Цель: Научиться составлять Java-приложения для мобильных устройств.
Задача:
Составить программу на языке программирования Java, для мобильных устройств, реализует функции:
2 |
arcctg x |
tg x |
Листинг программы:
package lr_10;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Midlet extends MIDlet implements CommandListener{
private Form mainForm;
private Display display;
private TextField x;
private Command ok;
private Command back;
public Midlet()
{
x = new TextField("x:", "", 10, TextField.NUMERIC);
// label - item label
// text - the initial contents, or null if the TextField is to be empty
// maxSize - the maximum capacity in characters
// NUMERIC - only numbers
ok = new Command("OK", Command.OK, 2);
back = new Command("Back", Command.OK, 2);
}
public void startApp()
{
display = Display.getDisplay(this);
mainForm = new Form("Text Field");
mainForm.append("Блажко Виктория, вариант 2.");
mainForm.append(x);
mainForm.addCommand(ok);
mainForm.setCommandListener(this);
display.setCurrent(mainForm);
}
public void showInput(){
display = Display.getDisplay(this);
String n = x.getString();
Form form = new Form("Input Value");
form.append(n);
double arctg_x = arctan(Double.parseDouble(n));
form.append("\narctg(x)= "+arctg_x);
double tg_x = Math.tan(Double.parseDouble(n));
form.append("\ntg(x)= "+tg_x);
form.addCommand(back);
form.setCommandListener(this);
display.setCurrent(form);
}
public void goBack()
{
display = Display.getDisplay(this);
display.setCurrent(mainForm);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
exitapp();
}
public void exitapp()
{
// Сюди слід додати код, який буде виконуватися
// при закритті програми.
notifyDestroyed(); // знищення Midlet-А
}
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if(label.equals("OK"))
{
showInput();
}
if(label.equals("Back")){
goBack();
}
}public double arctan(double x) {
if (Math.abs(x) == 1)return sgn(x) * Math.PI / 4;
if (Math.abs(x) > 1)return sgn(x) * Math.PI / 2 - arctan(1 / x);
double R = 0;
for (int n = 0; n < 100; n++) R += pow( -1, n) * pow(x, 2 * n + 1) / (2 * n + 1);
return R;
}
public byte sgn(double x) {
if (x < 0)return -1;
if (x == 0)return 0;
return 1;
}
public double pow(double a, int b) {
if (a == 0 && b == 0)return Double.NaN;
if (b == 0)return 1;
if (b == 1)return a;
if (b == -1)return 1 / a;
if (b < 0)return (1 / pow(a, -b));
double R = 1;
while (b != 0) {
if (b % 2 != 0) R *= a;
a *= a;
b /= 2;
}
return R;
}
}
Р езультат:
Вывод: я научился составлять Java-приложения для мобильных устройств.