
Последние записи
- Убить процесс
- Конвертер heic в jpg
- Проверка на шестнадцатеричный формат записи
- Отдать пользователю файл с помощью file_get_contents()
- Написать собственую функцию operator[] для битов
- Проблема с движением 2D человека
- OpenGl.Создание винтовой лестницы
- Склеить несколько файлов в один
- Windows 10 сменить администратора
- Рандомное слайдшоу

Интенсив по Python: Работа с API и фреймворками 24-26 ИЮНЯ 2022. Знаете Python, но хотите расширить свои навыки?
Slurm подготовили для вас особенный продукт! Оставить заявку по ссылке - https://slurm.club/3MeqNEk

Online-курс Java с оплатой после трудоустройства. Каждый выпускник получает предложение о работе
И зарплату на 30% выше ожидаемой, подробнее на сайте академии, ссылка - ttps://clck.ru/fCrQw
4th
Ноя
Java апплет — измерение коэффициента вязкости жидкости
Posted by maloy under Java, Архив, Заметки, Исходники, Пост-обзор
Среда разработки Eclipse.
И так…
1. Виртуальный практикум.
Опыт по физике, измерение коэффициента вязкости жидкости.
public class ball extends Applet implements ActionListener, Runnable { public ball() { timeOn = false; timerOn = false; timerValue = 0.0D; timeStep = 1.0D; firstStart = true; AppletOn = false; menuY = 0; time = 0.0D; mtimer = null; a = 1.0D; k = 1.0D; r = 2.5D; } void LoadGraphics() { MediaTracker mediatracker = new MediaTracker(this); showStatus("Loading images..."); System.out.println("Loading images..."); backgrnd = getImage(getDocumentBase(), "img/back.jpg"); mediatracker.addImage(backgrnd, 1); lead1 = getImage(getDocumentBase(), "img/lead1.gif"); mediatracker.addImage(lead1, 2); lead2 = getImage(getDocumentBase(), "img/lead2.gif"); mediatracker.addImage(lead2, 3); lead3 = getImage(getDocumentBase(), "img/lead3.gif"); mediatracker.addImage(lead3, 4); steel1 = getImage(getDocumentBase(), "img/steel1.gif"); mediatracker.addImage(steel1, 5); steel2 = getImage(getDocumentBase(), "img/steel2.gif"); mediatracker.addImage(steel2, 6); steel3 = getImage(getDocumentBase(), "img/steel3.gif"); mediatracker.addImage(steel3, 7); try { mediatracker.waitForAll(); System.out.println("loaded"); } catch(InterruptedException _ex) { } showStatus("Ready"); } public void actionPerformed(ActionEvent actionevent) { if(actionevent.getActionCommand().equals("Start") || actionevent.getActionCommand().equals("Start position")) { double d; if(gr_ball.getCurrent().getLabel().equals("lead")) { d = 11.4D; ball1 = lead1; ball2 = lead2; ball3 = lead3; } else { d = 7.7999999999999998D; ball1 = steel1; ball2 = steel2; ball3 = steel3; } double d1; double d2; if(gr_liquid.getCurrent().getLabel().equals("glycerine")) { d1 = 1.26D; if(temperature.getCurrent().getLabel().equals("T=283K")) d2 = 3950D; else if(temperature.getCurrent().getLabel().equals("T=293K")) d2 = 1480D; else if(temperature.getCurrent().getLabel().equals("T=303K")) d2 = 600D; else if(temperature.getCurrent().getLabel().equals("T=313K")) d2 = 330D; else d2 = 180D; } else { d1 = 0.95999999999999996D; d2 = 987D; } r = (double)Math.round(15D + 10D * Math.random()) / 10D; piccoef = 50D / r / 18D; a = (1.0D - d1 / d) * 9.8100000000000005D; k = (450D * d2) / r / r / d; if(rEdit != null) rEdit.setText(String.valueOf(r)); } if(actionevent.getActionCommand().equals("Start")) { if(firstStart) firstStart = false; time = 0.0D; start(); } else if(actionevent.getActionCommand().equals("Start position")) { time = 0.0D; timerValue = 0.0D; timerValueEdit.setText("0"); stop(); } else if(actionevent.getActionCommand().equals("Timer")) { if(timerOn) { timerOn = false; } else { timerValue = 0.0D; timerOn = true; } } else if(actionevent.getActionCommand().equals("Stop")) { stop(); timerOn = false; } recalc(); repaint(); }
public void init() { setLayout(null); setSize(570, 450); setBackground(new Color(0xc0c0c0)); menuY += 5; StartButton = new Button(); StartButton.setLabel("Start"); StartButton.setBounds(5, menuY, 50, 20); StartButton.setBackground(new Color(0xc0c0c0)); StartButton.addActionListener(this); add(StartButton); StopButton = new Button(); StopButton.setLabel("Stop"); StopButton.setBounds(65, menuY, 50, 20); StopButton.setBackground(new Color(0xc0c0c0)); StopButton.addActionListener(this); add(StopButton); menuY += 30; TimerButton = new Button(); TimerButton.setLabel("Timer"); TimerButton.setBounds(5, menuY, 50, 20); TimerButton.setBackground(new Color(0xc0c0c0)); TimerButton.addActionListener(this); add(TimerButton); timerValueEdit = new TextField(); timerValueEdit.setEditable(false); timerValueEdit.setText("0"); timerValueEdit.setBounds(65, menuY, 50, 20); add(timerValueEdit); menuY += 30; ResetButton = new Button(); ResetButton.setLabel("Start position"); ResetButton.setBounds(5, menuY, 110, 20); ResetButton.setBackground(new Color(0xc0c0c0)); ResetButton.addActionListener(this); add(ResetButton); menuY += 30; timeStep = 12D; gr_ball = new CheckboxGroup(); gr_liquid = new CheckboxGroup(); temperature = new CheckboxGroup(); lead = new Checkbox("lead", gr_ball, true); steel = new Checkbox("steel", gr_ball, false); glycerine = new Checkbox("glycerine", gr_liquid, true); kerosene = new Checkbox("castor oil", gr_liquid, false); t1 = new Checkbox("T=283K", temperature, true); t2 = new Checkbox("T=293K", temperature, false); t3 = new Checkbox("T=303K", temperature, false); t4 = new Checkbox("T=313K", temperature, false); t5 = new Checkbox("T=323K", temperature, false); lead.setBounds(5, menuY, 100, 15); menuY += 30; steel.setBounds(5, menuY, 100, 15); menuY += 30; glycerine.setBounds(5, menuY, 100, 15); menuY += 30; kerosene.setBounds(5, menuY, 100, 15); menuY += 30; t1.setBounds(5, menuY, 100, 15); menuY += 30; t2.setBounds(5, menuY, 100, 15); menuY += 30; t3.setBounds(5, menuY, 100, 15); menuY += 30; t4.setBounds(5, menuY, 100, 15); menuY += 30; t5.setBounds(5, menuY, 100, 15); menuY += 30; add(lead); add(steel); add(glycerine); add(kerosene); add(t1); add(t2); add(t3); add(t4); add(t5); rLabel = new Label("r (10^-4 m)"); rLabel.setBounds(5, menuY, 55, 15); add(rLabel); rEdit = new TextField(); rEdit.setEditable(false); rEdit.setText("2.5"); rEdit.setBounds(65, menuY, 50, 20); add(rEdit); menuY += 30; heightLabel = new Label("height (cm)"); heightLabel.setBounds(5, menuY, 50, 15); add(heightLabel); HeightEdit = new TextField(); HeightEdit.setText("0"); HeightEdit.setBounds(65, menuY, 50, 17); add(HeightEdit); menuY += 30; backbuf = createImage(570, 450); LoadGraphics(); ball1 = lead1; ball2 = lead2; ball3 = lead3; r = (double)Math.round(15D + 10D * Math.random()) / 10D; piccoef = 50D / r / 18D; recalc(); } public void paint(Graphics g) { g.translate(120, 0); g.drawImage(backgrnd, 0, 0, this); if((48D - r * 18D) + x * 294D < 22D) g.drawImage(ball1, (int)(235D - r * 9D), (int)((48D - r * 18D) + x * 294D), (int)(235D + r * 9D), 23, 0, 0, ball1.getWidth(this), (int)(((-25D + r * 18D) - x * 294D) * piccoef), this); if((48D - r * 18D) + x * 294D <= 22D) g.drawImage(ball2, (int)(235D - r * 9D), 23, (int)(235D + r * 9D), 48, 0, (int)(((-25D + r * 18D) - x * 294D) * piccoef), ball1.getWidth(this), (int)((r * 18D - x * 294D) * piccoef), this); else if(-r * 18D + x * 294D < -1D) g.drawImage(ball2, (int)(235D - r * 9D), (int)((48D - r * 18D) + x * 294D), (int)(235D + r * 9D), 48, 0, 0, ball1.getWidth(this), (int)((r * 18D - x * 294D) * piccoef), this); if(-r * 18D + x * 294D < 0.0D) g.drawImage(ball3, (int)(235D - r * 9D), 48, (int)(235D + r * 9D), (int)(48D + x * 294D), 0, (int)((r * 18D - x * 294D) * piccoef), ball1.getWidth(this), ball1.getHeight(this), this); else g.drawImage(ball3, (int)(235D - r * 9D), (int)((48D - r * 18D) + x * 294D), (int)(235D + r * 9D), (int)(48D + x * 294D), 0, 0, ball1.getWidth(this), ball1.getHeight(this), this); g.setColor(new Color(0, 0, 0)); }
void recalc() { x = ((a / k / k) * Math.exp(-k * time) + (a / k) * time) - a / k / k; if(x > 1.1499999999999999D) x = 1.1499999999999999D; Double double1 = new Double(x); if(HeightEdit != null) HeightEdit.setText(double1.toString()); } public void run() { do try { if(timeOn) time += timeStep; if(timerOn) { timerValue += timeStep; timerValue = (double)Math.round(timerValue * 10D) / 10D; timerValueEdit.setText(String.valueOf(timerValue)); } recalc(); repaint(); Thread.sleep(100L); } catch(InterruptedException _ex) { stop(); } while(true); } public void start() { if(!firstStart) { timeOn = true; if(mtimer == null) { mtimer = new Thread(this); mtimer.start(); } } } public void stop() { if(mtimer != null) { mtimer.stop(); mtimer = null; } } public void update(Graphics g) { paint(backbuf.getGraphics()); g.drawImage(backbuf, 0, 0, this); } private Button StartButton; private Button StopButton; private Button ResetButton; private Button TimerButton; private TextField timerValueEdit; private boolean timeOn; protected boolean timerOn; protected double timerValue; protected double timeStep; private static final int WIDTH = 450; private static final int HEIGHT = 450; private static final int TaskBar = 120; private boolean firstStart; private boolean AppletOn; private int oldX; private int oldY; protected int menuY; protected double time; Image backbuf; Thread mtimer; Checkbox lead; Checkbox steel; Checkbox glycerine; Checkbox kerosene; Checkbox t1; Checkbox t2; Checkbox t3; Checkbox t4; Checkbox t5; CheckboxGroup gr_ball; CheckboxGroup gr_liquid; CheckboxGroup temperature; Label rLabel; TextField rEdit; Label heightLabel; TextField HeightEdit; double a; double k; double r; final double nk = 987D; final double ng1 = 3950D; final double ng2 = 1480D; final double ng3 = 600D; final double ng4 = 330D; final double ng5 = 180D; final double rg = 1.26D; final double rk = 0.95999999999999996D; final double rl = 11.4D; final double rs = 7.7999999999999998D; double piccoef; Image backgrnd; Image lead1; Image lead2; Image lead3; Image steel1; Image steel2; Image steel3; Image ball1; Image ball2; Image ball3; double x; }
тот же пример с графикой смотри в теме
тема на форуме от 2008 года
Случайные статьи
Купить рекламу на сайте за 1000 руб
пишите сюда - alarforum@yandex.ru
Да и по любым другим вопросам пишите на почту

пеллетные котлы

Пеллетный котел Emtas

Наши форумы по программированию:
- Форум Web программирование (веб)
- Delphi форумы
- Форумы C (Си)
- Форум .NET Frameworks (точка нет фреймворки)
- Форум Java (джава)
- Форум низкоуровневое программирование
- Форум VBA (вба)
- Форум OpenGL
- Форум DirectX
- Форум CAD проектирование
- Форум по операционным системам
- Форум Software (Софт)
- Форум Hardware (Компьютерное железо)