「lshjava实现」java实现
本篇文章给大家谈谈lshjava实现,以及java实现对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、求Java计算器标准的布局代码
- 2、电脑计算器中的Exp、Lsh、dms、Hot、Xor、Pi都表示什么计算功能
- 3、LSH是什么意思
- 4、高手帮我用JAVA写个简单计算器嘛 谢谢
- 5、java怎么实现window计算器上的Lsh键
求Java计算器标准的布局代码
是用awt和swing做的,很好看比单单用AWT做好看
import java.awt.*;
import javax.swing.*;
public class Conputer extends JFrame {
protected Container con = getContentPane();// 指向内容面板
protected JMenuBar a = new JMenuBar();// 菜单条
protected JMenu a1 = new JMenu("编辑(E)");// 菜单1
protected JMenu a2 = new JMenu("查看(V)");// 菜单2
protected JMenu a3 = new JMenu("帮助(H)");// 菜单3
protected JMenuItem a11 = new JMenuItem("复制(C)", 'C');// 菜单1的菜单项
protected JMenuItem a12 = new JMenuItem("粘贴(P)", 'P');// 菜单1的菜单项
protected JMenuItem a21 = new JMenuItem("标准型(T)", 'T');// 菜单2的菜单项
protected JMenuItem a22 = new JMenuItem("科学型(S)", 'S');// 菜单2的菜单项
protected JMenuItem a31 = new JMenuItem("帮助主题(H)", 'H');// 菜单3的菜单项
protected JTextField jtf = new JTextField(30);// 文本框
protected JButton[] jb = new JButton[27];
protected String[] arr = { "Backspace", "CE", "C", "MC", "7", "8", "9", "/", "sqrt",
"MR", "4", "5", "6", "*", "%", "MS", "1", "2", "3", "-", "1/x",
"M+", "0", "+/-", ".", "+", "=" };
protected JPanel jp = new JPanel();// 主面板
protected JPanel m = new JPanel();// 次面板
protected JPanel m1 = new JPanel();// 次次面板
protected JPanel m2 = new JPanel();// 次次面板
protected JPanel m3 = new JPanel();// 次次面板
protected JPanel m4 = new JPanel();// 次次面板
protected JPanel m5 = new JPanel();// 次次面板
protected JPanel m6 = new JPanel();// 次次面板
protected GridLayout glo = new GridLayout(6, 1, 3, 3);// 主网格布局
protected GridLayout glo1 = new GridLayout(1, 3, 3, 3);// 次网格布局
protected GridLayout glo2 = new GridLayout(1, 6, 3, 3);// 次网格布局
protected Conputer(String s) {
super(s);
a1.setMnemonic('E');
a1.add(a11);
a1.add(a12);
a2.setMnemonic('V');
a2.add(a21);
a2.add(a22);
a3.setMnemonic('H');
a3.add(a31);
a.add(a1);
a.add(a2);
a.add(a3);
this.setJMenuBar(a);// 菜单条完成
for (int i = 0; i 27; i++) {
jb[i] = new JButton(arr[i]);
}
jp.setLayout(glo);
jp.add(m1);
m1.add(jtf);
jtf.setEditable(false); jtf.setText("0."); jtf.setForeground(Color.BLUE); jtf.setBackground(Color.WHITE);
jtf.setHorizontalAlignment(JTextField.RIGHT);//文本显示在右边
jp.add(m2);
m2.setLayout(glo1);
m2.add(jb[0]);
m2.add(jb[1]);
m2.add(jb[2]);
jp.add(m3);
m3.setLayout(glo2);
m3.add(jb[3]);
m3.add(jb[4]);
m3.add(jb[5]);
m3.add(jb[6]);
m3.add(jb[7]);
m3.add(jb[8]);
jp.add(m4);
m4.setLayout(glo2);
m4.add(jb[9]);
m4.add(jb[10]);
m4.add(jb[11]);
m4.add(jb[12]);
m4.add(jb[13]);
m4.add(jb[14]);
jp.add(m5);
m5.setLayout(glo2);
m5.add(jb[15]);
m5.add(jb[16]);
m5.add(jb[17]);
m5.add(jb[18]);
m5.add(jb[19]);
m5.add(jb[20]);
jp.add(m6);
m6.setLayout(glo2);
m6.add(jb[21]);
m6.add(jb[22]);
m6.add(jb[23]);
m6.add(jb[24]);
m6.add(jb[25]);
m6.add(jb[26]);
m.add(jp);
con.add(m);
this.setResizable(false);// 不能用鼠标拉伸窗体
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//可以关闭窗体
this.setSize(380, 275);
this.setVisible(true);
}
protected Conputer() {
this("计算器");
}
public static void main(String[] args) {
new Conputer("计算器");
}
}
电脑计算器中的Exp、Lsh、dms、Hot、Xor、Pi都表示什么计算功能
老问题,问问有问过的。。。1.Exp是幂指数函数,算式为(x)exp(y),代表x.e+y,
比如1exp1,就是1.e+1=10;2.Lsh为左移。该功能主要针对二进制数,在单击Lsh按钮后,必须指定要将显示区中的数字左移或右移多少位,然后单击“=”实现移位;3.dms将显示数字转换为度-分-秒格式(假设显示数字是用度数表示的),只能用于十进制字系统;4.not是做按位取反逻辑运算;5.xor是做按位取异或逻辑运算;6.Pi用来显示圆周率Pi值,只用于十进制系统。
LSH是什么意思
J2EE架构:依通自主开发的LSH软件架构。LSH框架对于对数据安全性要求较高,界面设计可变性的需求,把交互系统的组成分解成模型、视图、控制三种部件。
1、模型部件是软件所处理问题逻辑在独立于外在显示内容和形式情况下的内在抽象,封装了问题的核心数据、逻辑和功能的计算关系,他独立于具体的界面表达和I/O操作。
2、视图部件把表示模型数据及逻辑关系和状态的信息及特定形式展示给用户。它从模型获得显示信息,对于相同的信息可以有多个不同的显示形式或视图。
3、控制部件是处理用户与软件的交互操作的,其职责是控制提供模型中任何变化的传播,确保用户界面于模型间的对应联系;它接受用户的输入,将输入反馈给模型,进而实现对模型的计算控制,是使模型和视图协调工作的部件。通常一个视图具有一个控制器。
模型、视图与控制器的分离,使得一个模型可以具有多个显示视图。如果用户通过某个视图的控制器改变了模型的数据,所有其它依赖于这些数据的视图都应反映到这些变化。因此,无论何时发生了何种数据变化,控制器都会将变化通知所有的视图,导致显示的更新。
高手帮我用JAVA写个简单计算器嘛 谢谢
import java.awt.*;
import java.awt.event.*;
import java.math.BigDecimal;
class Calculator {
private Frame frame;
private Panel panel[] = new Panel[6];
private Button botton[] = new Button[25];
private TextField textField;
private final String string[] = { "1", "2", "3", "clear", "exit", "4", "5",
"6", "+", "-", "7", "8", "9", "*", "/", "0", ".", "sqr", "%",
"+/-", "sin", "cos", "tan", "PI", "=" };
private String str1, str2, optype;
private final Label label = new Label(
"Contact me--QQ:120355282 , mail:fsolsh@gmail.com");
private final String STR1 = "Please enter your data!";
private final String STR2 = "Arithmetic data can't be '0'!";
private double result = 0;
private void go() {
frame = new Frame("Welcome ! Author:Fsol-sh JSface");
frame.setResizable(false);
frame.setLayout(new GridLayout(7, 1, 5, 5));
for (int i = 0; i botton.length; i++) {
botton[i] = new Button(string[i]);
botton[i].setForeground(Color.BLUE);
botton[i].setFont(new Font("", Font.BOLD, 12));
}
textField = new TextField(40);
textField.setFont(new Font("", Font.BOLD, 12));
textField.setEditable(false);
label.setAlignment(1);
label.setFont(new Font("", Font.BOLD, 12));
label.setForeground(Color.BLUE);
for (int i = 0; i panel.length; i++) {
panel[i] = new Panel();
frame.add(panel[i]);
}
frame.add(label);
panel[0].add(textField);
for (int i = 1; i 6; i++) {
panel[i].setLayout(new GridLayout(1, 5, 5, 5));
for (int j = (i - 1) * 5; j i * 5; j++) {
panel[i].add(botton[j]);
}
}
for (int i = 0; i 3; i++) {
for (int j = (i) * 5; j i * 5 + 3; j++) {
buttonSet(botton[j]);
}
}
botton[3].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText("");
}
});
botton[4].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
operateTypeSet(botton[8]);
operateTypeSet(botton[9]);
operateTypeSet(botton[13]);
operateTypeSet(botton[14]);
operateTypeSet(botton[18]);
botton[15].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (check(textField.getText())
|| textField.getText().equals("0")) {
textField.setText("0");
} else
textField.setText(textField.getText() + "0");
}
});
botton[16].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (check(textField.getText())) {
textField.setText(STR1);
} else if (textField.getText().indexOf(".") == -1) {
textField.setText(textField.getText() + ".");
} else
textField.setText(textField.getText());
}
});
botton[17].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (check(textField.getText())) {
textField.setText(STR1);
} else
textField.setText(""
+ Math
.sqrt(Double.parseDouble(textField
.getText())));
}
});
botton[19].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str = textField.getText();
if (check(str)) {
textField.setText(STR1);
} else if (isZero(str)) {
textField.setText(str);
} else if (str.indexOf("-") != -1) {
StringBuffer sb = new StringBuffer(str);
sb = sb.deleteCharAt(sb.indexOf("-"));
str = new String(sb);
textField.setText(str);
} else
textField.setText("-" + str);
}
});
botton[20].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (check(textField.getText())) {
textField.setText(STR1);
} else
textField
.setText(""
+ Math.sin(Double.parseDouble(textField
.getText())));
}
});
botton[21].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (check(textField.getText())) {
textField.setText(STR1);
} else
textField
.setText(""
+ Math.cos(Double.parseDouble(textField
.getText())));
}
});
botton[22].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (check(textField.getText())) {
textField.setText(STR1);
} else
textField
.setText(""
+ Math.tan(Double.parseDouble(textField
.getText())));
}
});
botton[23].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText("" + Math.PI);
}
});
botton[24].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
str2 = textField.getText();
if (check(str2)) {
textField.setText(STR1);
} else if (isZero(str2) "/".equals(optype)) {
textField.setText(STR2);
} else {
operate(str1, str2);
textField.setText("" + result);
str1 = "";
str2 = "";
optype = "=";
}
}
});
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
private void operateTypeSet(final Button opbutton) {
opbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
str1 = textField.getText();
if (check(str1)) {
str1 = "";
optype = null;
textField.setText(STR1);
} else {
textField.setText("");
optype = opbutton.getLabel();
}
}
});
}
private void buttonSet(final Button b) {
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (check(textField.getText())) {
textField.setText(b.getLabel());
} else {
textField.setText(textField.getText() + b.getLabel());
}
}
});
}
private boolean check(String param) {
return isNullOrEmpty(param) || STR1.equals(param) || STR2.equals(param);
}
private boolean isZero(String param) {
if (!isNullOrEmpty(param)) {
BigDecimal bigDecimal = new BigDecimal(param);
return bigDecimal.compareTo(new BigDecimal(0)) == 0;
} else {
return false;
}
}
private boolean isNullOrEmpty(String param) {
return param == null || param.trim().length() == 0;
}
private double operate(String param1, String param2) {
if (optype == "+") {
result = Double.parseDouble(param1) + Double.parseDouble(param2);
} else if (optype == "-") {
result = Double.parseDouble(param1) - Double.parseDouble(param2);
} else if (optype == "*") {
result = Double.parseDouble(param1) * Double.parseDouble(param2);
} else if (optype == "/") {
result = Double.parseDouble(param1) / Double.parseDouble(param2);
} else if (optype == "%") {
result = Double.parseDouble(param1) % Double.parseDouble(param2);
} else {
result = Double.parseDouble(param2);
}
return this.result;
}
public static void main(String[] args) {
Calculator calculator = new Calculator();
calculator.go();
}
}
java怎么实现window计算器上的Lsh键
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class JiSuanQi extends JFrame implements ActionListener{
private String calculateNum = "";
private String current = "";
private String yunSuanFu = "";
private String buttons[][] = {{"清零","10"},{"0","0"},{"=","11"},{"+","12"},
{"1","1"},{"2","2"},{"3","3"},{"-","13"},{"4","4"},{"5","5"},{"6","6"},
{"*","14"},{"7","7"},{"8","8"},{"9","9"},{"/","15"}};
JTextField jtf;
public JiSuanQi(){
setSize(300, 300);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buJu();
}
private void buJu(){
jtf = new JTextField();
jtf.setSize(283, 40);
jtf.setLocation(5, 5);
jtf.setEditable(false);
jtf.setHorizontalAlignment(JTextField.RIGHT);
add(jtf);
JPanel jp = new JPanel();
jp.setLayout(new GridLayout(4,4));
jp.setSize(283, 200);
jp.setLocation(5,50);
for(int i = 0;i buttons.length;i++){
Button b = new Button(buttons[i][0]);
b.setName(buttons[i][1]);
b.addActionListener(this);
jp.add(b);
}
add(jp);
}
public void actionPerformed(ActionEvent s) {
// TODO Auto-generated method stub
Button b = (Button)s.getSource();
String name = b.getName();
if(Integer.valueOf(name) = 9){
if(current.equals("0")){
if(name.equals("0"))
return;
current = "";
}
current += name;
jtf.setText(current);
}else if(name.equals("10")){
current = "";
calculateNum = "";
yunSuanFu = "";
jtf.setText("0");
}else if(name.equals("11")){
if(!calculateNum.equals("") !yunSuanFu.equals("")){
double one = Double.valueOf(calculateNum);
double two = 0;
double sourse = 0;
if(current.equals(""))
two = one;
two = Double.valueOf(current);
if(yunSuanFu.equals("12")){
sourse = one + two;
}else if(yunSuanFu.equals("13")){
sourse = one - two;
}else if(yunSuanFu.equals("14")){
sourse = one * two;
}else if(yunSuanFu.equals("15")){
if(two == 0){
jtf.setText("除数不能为0");
return;
}
sourse = one / two;
}
calculateNum = String.valueOf(sourse);
jtf.setText(String.valueOf(sourse));
}
}else{
if(!calculateNum.equals("") || !current.equals("")){
if(calculateNum.equals(""))
calculateNum = current;
current = "";
yunSuanFu = name;
jtf.setText(b.getLabel());
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JiSuanQi jsq = new JiSuanQi();
jsq.setVisible(true);
}
}
lshjava实现的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java实现、lshjava实现的信息别忘了在本站进行查找喔。
发布于:2022-12-24,除非注明,否则均为
原创文章,转载请注明出处。