import javaxswing;
import javaawt;
import javaawtevent;
public class Calculator extends JFrame implements ActionListener
{
private boolean dotExist, operated, equaled; // 帮助运算的布尔变量
private double storedNumber; // 目前的结果
private char lastOperator; // 表示上一运算符
private JTextField operation; // 结果栏
private JButton dot, plus, minus, multi, div, sqrt, equal, changePN, clear; // 运算符
private JButton[] numbers; // 数字
// 构造者
public Calculator()
{
setTitle("Calculator");
// 初始化变量
dotExist = false; // 表示当前的数是否有小数点
operated = false; // 表示任意运算符是否被按下
equaled = false; // 表示等号是否被按下
storedNumber = 0;
lastOperator = '';
// 初始化窗口变量
operation = new JTextField("0");
operationsetEditable(false);
numbers = new JButton[10];
for (int i = 0; i < 10; i++)
numbers[i] = new JButton("" + i);
dot = new JButton("");
plus = new JButton("+");
minus = new JButton("-");
multi = new JButton("");
div = new JButton("/");
sqrt = new JButton("√");
equal = new JButton("=");
changePN = new JButton("±");
clear = new JButton("AC");
// 将窗口物体放入窗口
GridBagLayout layout = new GridBagLayout();
getContentPane()setLayout(layout);
addComponent(layout, operation, 0, 0, 4, 1);
addComponent(layout, numbers[1], 1, 0, 1, 1);
addComponent(layout, numbers[2], 1, 1, 1, 1);
addComponent(layout, numbers[3], 1, 2, 1, 1);
addComponent(layout, numbers[4], 2, 0, 1, 1);
addComponent(layout, numbers[5], 2, 1, 1, 1);
addComponent(layout, numbers[6], 2, 2, 1, 1);
addComponent(layout, numbers[7], 3, 0, 1, 1);
addComponent(layout, numbers[8], 3, 1, 1, 1);
addComponent(layout, numbers[9], 3, 2, 1, 1);
addComponent(layout, dot, 4, 0, 1, 1);
addComponent(layout, numbers[0], 4, 1, 1, 1);
addComponent(layout, sqrt, 4, 2, 1, 1);
addComponent(layout, plus, 1, 3, 1, 1);
addComponent(layout, minus, 2, 3, 1, 1);
addComponent(layout, multi, 3, 3, 1, 1);
addComponent(layout, div, 4, 3, 1, 1);
addComponent(layout, equal, 5, 0, 2, 1);
addComponent(layout, changePN, 5, 2, 1, 1);
addComponent(layout, clear, 5, 3, 1, 1);
}
// 对按钮进行反应的方法
public void actionPerformed(ActionEvent e)
{
JButton btn = (JButton)egetSource();
if (btn == clear)
{
operationsetText("0");
dotExist = false;
storedNumber = 0;
lastOperator = '';
}
else if (btn == equal)
{
operate('=');
equaled = true;
}
else if (btn == plus)
{
operate('+');
equaled = false;
}
else if (btn == minus)
{
operate('-');
equaled = false;
}
else if (btn == multi)
{
operate('');
equaled = false;
}
else if (btn == div)
{
operate('/');
equaled = false;
}
else if (btn == changePN)
{
operate('p');
operate('=');
equaled = true;
}
else if (btn == sqrt)
{
operate('s');
operate('=');
equaled = true;
}
else
{
if (equaled)
storedNumber = 0;
for (int i = 0; i < 10; i++)
if (btn == numbers[i])
{
if (operationgetText()equals("0"))
operationsetText("" + i);
else if(! operated)
operationsetText(operationgetText() + i);
else
{
operationsetText("" + i);
operated = false;
}
}
if (btn == dot && ! dotExist)
{
operationsetText(operationgetText() + "");
dotExist = true;
}
}
}
// 进行运算的方法
private void operate(char operator)
{
double currentNumber = DoublevalueOf(operationgetText())doubleValue();
if (lastOperator == '')
storedNumber = currentNumber;
else if (lastOperator == '+')
storedNumber += currentNumber;
else if (lastOperator == '-')
storedNumber -= currentNumber;
else if (lastOperator == '')
storedNumber = currentNumber;
else if (lastOperator == '/')
storedNumber /= currentNumber;
else if (lastOperator == 'p')
storedNumber = -1;
else if (lastOperator == 's')
storedNumber = Mathsqrt(currentNumber);
else if (lastOperator == '=' && equaled)
storedNumber = currentNumber;
operationsetText("" + storedNumber);
operated = true;
lastOperator = operator;
}
// 快捷使用GridBagLayout的方法
private void addComponent(GridBagLayout layout, Component component, int row, int col, int width, int height)
{
GridBagConstraints constraints = new GridBagConstraints();
constraintsfill = GridBagConstraintsBOTH;
constraintsinsets = new Insets(10, 2, 10, 2);
constraintsweightx = 100;
constraintsweighty = 100;
constraintsgridx = col;
constraintsgridy = row;
constraintsgridwidth = width;
constraintsgridheight = height;
layoutsetConstraints(component, constraints);
if (component instanceof JButton)
((JButton)component)addActionListener(this);
getContentPane()add(component);
}
// 主方法初始化并显示窗口
public static void main(String[] args)
{
Calculator calc = new Calculator();
calcsetSize(290, 400);
calcsetVisible(true);
}
}
如果你想加sin cos tan的话就建它们的按钮 在actionPerformed方法中的if-else语句中加else if (btn == sin){operate('S');operate('=');equaled = true;}然后在operate方法加对应的语句就行了记忆M+, M-没时间搞 这个应该比较简单容易明白吧
>
searchwxml部分内容:
<view class='search_box page_row'>
<view class='search'>
<view class='search_item'>
<icon class='search_icon' size='20' type='search'></icon>
<input value='' placeholder='搜索您要找的商品' bindinput='bindInput'/>
</view>
</view>
<view class='search_btn' bindtap='search'>搜索</view>
</view>
searchwxss样式部分:
search_box{width:100%;background:#2587f1;padding:0 0 10px;display: flex;flex-direction: row}
search{width: calc( 100% - 64rpx );}
search_item{border: 1px solid #d0d0d0;border-radius: 10rpx;margin-left: 20rpx;background:#fff;}
search_item input{margin-left: 60rpx;height: 60rpx;border-radius: 5px;background:#fff;}
search_btn{width: 15%;height: 60rpx;line-height:60rpx;text-align: center;background:transparent;color:#fff;}
search_icon{margin: 10rpx 10rpx 10rpx 10rpx;position: absolute;left:25rpx;z-index: 2;width: 20px;height: 20px;text-align: center;}
Calendar类有一个方法add方法可以使用,例如calendaradd(CalendarWEEK_OF_YEAR, -1);表示把时间向上推一周,calendaradd(CalendarYEAR, -1);表示把时间向上推一年。下面是一个具体的实例:
public class DateCalcTest
{
public static void main(String[] args)
{
Calendar calendar = CalendargetInstance();
Date date = new Date(SystemcurrentTimeMillis());
calendarsetTime(date);
// calendaradd(CalendarWEEK_OF_YEAR, -1);
calendaradd(CalendarYEAR, -1);
date = calendargetTime();
Systemoutprintln(date);
}
}
class Program
{
static void Main(string[] args)
{
Angle MyJuge = new Angle();
ConsoleWrite("请输入三角形的三个边:");
double a, b, c;
a= doubleParse (ConsoleReadLine());
b = doubleParse (ConsoleReadLine());
c= doubleParse (ConsoleReadLine());
if (a <= 0 || b <= 0 || c <= 0)
{
ConsoleWriteLine("请正确输入三角形的边长,边长必须为大于零的数!");
}
else
{
MyJugeTheJudge(a,b,c);
}
ConsoleReadLine();
}
}
class Angle
{
public void TheJudge(double a,double b,double c)
{
if (a + b > c && a + c > b && b + c > a)
{
ConsoleWriteLine("三个数可以构成一个三角形!");
if (a a == b b + c c || b b == a a + c c || c c == b b + a a)
{
ConsoleWriteLine("并且这三个数可以构成一个直角三角形!!");
if (a a == b b + c c)
ConsoleWriteLine("面积是:"+(bc/2)ToString ());
else if(b b == a a + c c)
ConsoleWriteLine("面积是:" + (a c / 2)ToString());
else if(c c == b b + a a)
ConsoleWriteLine("面积是:" + (a c / 2)ToString());
}
else
{
ConsoleWriteLine("但是不能构成一个直角三角形!!");
}
}
else
{
ConsoleWriteLine("这三个数不能构成一个三角形!");
}
}
}
我也只会做到这里,知道怎样实现任何一个输入框中没有输入文字有错误信息提示!!请你公布答案。
<view>{{min}}:{{sec}}</view>
//计时器,cycleTime为豪秒数
timerSec(cycleTime) {
var that = this
let intervalsec = null //倒计时函数
intervalsec = setInterval(function() {
cycleTime--;
thatsetData({
min: parseInt(cycleTime / 60) < 10 '0' + parseInt(cycleTime / 60) : parseInt(cycleTime / 60),
sec: (cycleTime % 60) < 10 '0' + (cycleTime % 60) : (cycleTime % 60),
})
if (cycleTime == 0) {
clearInterval(intervalsec)
}
}, 1000)
},
import javautilScanner;
public class SavingAccount {
public static double account = 3000;
public static double rate = 003;
public void update(double rate){
thisrate = rate;
}
//flag 用来计算年利息和月利息,flag等true计算月利息
public double calc(double account , double rate , boolean flag){
if(flag)
return account rate / 12;
return account rate;
}
static class Test{
public static void main(String[] args) {
Systemoutprintln("原始存款:"+SavingAccountaccount + " \n原始利率:" +SavingAccountrate );
SavingAccount sa = new SavingAccount();
Systemoutprintln("原始年利息:"+sacalc(SavingAccountaccount,SavingAccountrate,false));
Systemoutprintln("原始月利息:"+sacalc(SavingAccountaccount,SavingAccountrate,true));
Systemoutprintln("######请输入新的利率######");
Scanner scanner = new Scanner(Systemin);
saupdate(scannernextDouble());
Systemoutprintln("更新后的利率:"+SavingAccountrate);
Systemoutprintln("更新后的年利息:"+sacalc(SavingAccountaccount,SavingAccountrate,false));
Systemoutprintln("更新后的月利息:"+sacalc(SavingAccountaccount,SavingAccountrate,true));
//更新后的存款怎么算 你是多长时间更新一次
Systemoutprintln("更新后的存款:"+(SavingAccountaccount+sacalc(SavingAccountaccount,SavingAccountrate,false)));
}
}
}
不知道对不对,我理解的是这样的了
以上就是关于关于java Applet小程序全部的内容,包括:关于java Applet小程序、小程序包括uniapp针对安全区域env(safe-area-inset-*)兼容、如何在小程序导航栏放一个搜索框等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)