求一java程序,一个界面计算器源代码,跪求大神,有注释最好 。。import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class GUI extends JFrame implements ActionListener {//实现监听接口
JTextField field = new JTextField(15);
double num1=0,num2;
char op;
public GUI(){
setLayout(new BorderLayout(10,10));
JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
p1.add(new JLabel("计算框:"));
p1.add(field);
add(p1,BorderLayout.NORTH);
JPanel p2 = new JPanel(new GridLayout(4,1));
//添加按钮
JButton bt1 = new JButton("1");
JButton bt2 = new JButton("2");
JButton bt3 = new JButton("3");
JButton bt4 = new JButton("4");
JButton bt5 = new JButton("5");
JButton bt6 = new JButton("6");
JButton bt7 = new JButton("7");
JButton bt8 = new JButton("8");
JButton bt9 = new JButton("9");
JButton bt0 = new JButton("0");
JButton btDel = new JButton("Del");
JButton btEqual = new JButton("=");
p2.add(bt1);p2.add(bt2);
p2.add(bt3); p2.add(bt4);
p2.add(bt5); p2.add(bt6);
p2.add(bt7);p2.add(bt8);
p2.add(bt9);p2.add(bt0);
p2.add(btDel);p2.add(btEqual);
add(p2,BorderLayout.CENTER);
JPanel p3 = new JPanel(new GridLayout(0,1));
JButton bta = new JButton(" ");
JButton btb = new JButton("-");
JButton btc = new JButton("*");
JButton btd = new JButton("/");
p3.add(bta);p3.add(btb);
p3.add(btc);p3.add(btd);
add(p3,BorderLayout.EAST);
//添加监听器
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
bt4.addActionListener(this);
bt5.addActionListener(this);
bt6.addActionListener(this);
bt7.addActionListener(this);
bt8.addActionListener(this);
bt9.addActionListener(this);
bt0.addActionListener(this);
bta.addActionListener(this);
btb.addActionListener(this);
btc.addActionListener(this);
btd.addActionListener(this);
btDel.addActionListener(this);
btEqual.addActionListener(this);
}
//事件的响应
public void actionPerformed(ActionEvent e){
String str =e.getActionCommand();
String s1 = field.getText();
if(str!=" "str!="-"str!="*"str!="/"str!="="str!="Del"){//为数字按钮时
field.setText(s1 str);
}
else if(str=="Del"){//删除键
field.setText("");
str=null;
}
else if(str=="="){//等号按钮
s1 =field.getText();
String t2 ="";
int flag=0;//标记操作符的位置
if(s1.indexOf(" ")!=-1)
flag = s1.indexOf(" ");
if(s1.indexOf("-")!=-1)
flag = s1.indexOf("-");
if(s1.indexOf("*")!=-1)
flag = s1.indexOf("*");
if(s1.indexOf("/")!=-1)
flag = s1.indexOf("/");
for(int i=flag 1;is1.length();i)
{
t2 =s1.charAt(i);//获得第二个操作数
}
num2 =Double.parseDouble(t2);//将第二个操作数转换为double
switch(op){
case ' ': num1 =num2;break;
case '-': num1-=num2;break;
case '*': num1*=num2;break;
case '/': num1/=num2;break;
}
field.setText(s1 "=" num1 "");//显示在文本框里
}
else{//加减乘除符号
num1 = Double.parseDouble(field.getText());
field.setText(s1 str);
op = str.charAt(0);//获得操作符
}
}
public static void main(String[] args){
GUI frame =new GUI();
frame.setTitle("简易计算器");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,200);
//frame.pack();
frame.setVisible(true);
}
}
不懂再问
java登陆界面源代码是个类文件 , 怎样运行文件?下载jdk并安装,之后设置下环境变量 。然后直接在命令行运行就可以了(用命令java *(*代表类名))
急!急!求java计算器源代码 最后能出如图这样的界面并能运行 急啊 好的翻倍追加分啊import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class CalculatorGUI {
private Frame f;
private Panel p1, p2;
private Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9;
private Button bPoint, bAdd, bDec, bMul, bDiv, bCal;
private TextField tf;
private String s, op;
private Calculator cal = new Calculator();
private boolean ifOp;
public CalculatorGUI() {
f = new Frame("Calculator");
p1 = new Panel();
p2 = new Panel();
b0 = new Button("0");
b1 = new Button("1");
b2 = new Button("2");
b3 = new Button("3");
b4 = new Button("4");
b5 = new Button("5");
b6 = new Button("6");
b7 = new Button("7");
b8 = new Button("8");
b9 = new Button("9");
bPoint = new Button(".");
bAdd = new Button(" ");
bDec = new Button("-");
bMul = new Button("*");
bDiv = new Button("/");
bCal = new Button("=");
tf = new TextField(25);
tf.setEditable(false);
}
public void launchFrame() {
f.setSize(220, 160);
f.setResizable(false);
f.addWindowListener(new myWindowListener());
p1.setLayout(new FlowLayout(FlowLayout.CENTER));
p1.add(tf);
f.add(p1, BorderLayout.NORTH);
p2.setLayout(new GridLayout(4, 4));
b0.addActionListener(new setLabelText_ActionListener());
b1.addActionListener(new setLabelText_ActionListener());
b2.addActionListener(new setLabelText_ActionListener());
b3.addActionListener(new setLabelText_ActionListener());
b4.addActionListener(new setLabelText_ActionListener());
b5.addActionListener(new setLabelText_ActionListener());
b6.addActionListener(new setLabelText_ActionListener());
b7.addActionListener(new setLabelText_ActionListener());
b8.addActionListener(new setLabelText_ActionListener());
b9.addActionListener(new setLabelText_ActionListener());
bPoint.addActionListener(new setLabelText_ActionListener());
bAdd.addActionListener(new setOperator_ActionListener());
bDec.addActionListener(new setOperator_ActionListener());
bMul.addActionListener(new setOperator_ActionListener());
bDiv.addActionListener(new setOperator_ActionListener());
bCal.addActionListener(new setOperator_ActionListener());
p2.add(b7);
p2.add(b8);
p2.add(b9);
p2.add(bAdd);
p2.add(b4);
p2.add(b5);
p2.add(b6);
p2.add(bDec);
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(bMul);
p2.add(b0);
p2.add(bPoint);
p2.add(bCal);
p2.add(bDiv);
f.add(p2, BorderLayout.SOUTH);
f.setVisible(true);
}
public void setTextFieldText_Temp() {
if (tf.getText().length()15
(tf.getText().indexOf(".") == -1 || !s.equals("."))) {
tf.setText(tf.getText()s);
} else {
tf.setText((tf.getText()s).substring(0, 15));
}
}
public void setTextFieldText() {
if (ifOp) {
ifOp = false;
tf.setText("");
setTextFieldText_Temp();
} else {
setTextFieldText_Temp();
}
}
public static void main(String[] args) {
CalculatorGUI calculator = new CalculatorGUI();
calculator.launchFrame();
}
class myWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
class setLabelText_ActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Button tempB = (Button) e.getSource();
s = tempB.getLabel();
setTextFieldText();
}
}
class setOperator_ActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Button tempB = (Button) e.getSource();
op = tempB.getLabel();
if (op.equals(" ")) {
tf.setText(cal.opAdd(tf.getText()));
ifOp = true;
} else if (op.equals("-")) {
tf.setText(cal.opSubtract(tf.getText()));
ifOp = true;
} else if (op.equals("*")) {
tf.setText(cal.opMultiply(tf.getText()));
ifOp = true;
} else if (op.equals("/")) {
tf.setText(cal.opDivide(tf.getText()));
ifOp = true;
} else if (op.equals("=")) {
tf.setText(cal.opEquals(tf.getText()));
ifOp = true;
}
}
}
}
class Calculator {
private String result = "0";
private int op = 0, add = 1, sub = 2, mul = 3, div = 4;
private double stringToDouble(String x) {
double y = Double.parseDouble(x);
return y;
}
private void operate(String x) {
double x1 = stringToDouble(x);
double y = stringToDouble(result);
switch (op) {
case 0:
result = x;
break;
case 1:
result = String.valueOf(yx1);
break;
case 2:
result = String.valueOf(y - x1);
break;
case 3:
result = String.valueOf(y * x1);
break;
case 4:
if (x1 != 0) {
result = String.valueOf(y / x1);
} else {
result = "The divisor can't be zero!";
}
break;
}
}
public String opAdd(String x) {
operate(x);
op = add;
return result;
}
public String opSubtract(String x) {
operate(x);
op = sub;
return result;
}
public String opMultiply(String x) {
operate(x);
op = mul;
return result;
}
public String opDivide(String x) {
operate(x);
op = div;
return result;
}
public String opEquals(String x) {
operate(x);
op = 0;
return result;
}
public void opClean() {
op = 0;
result = "0";
}
}
JAVA 中 GUI登录界面设计源代码?import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login {
private JFrame frame = new JFrame("登录");
private Container c = frame.getContentPane();
private JTextField username = new JTextField();
private JPasswordField password = new JPasswordField();
private JButton ok = new JButton("确定");
private JButton cancel = new JButton("取消");
public Login(){
frame.setSize(300,200);
c.setLayout(new BorderLayout());
initFrame();
frame.setVisible(true);
}
【java添加界面源代码 java编写界面的代码】 private void initFrame() {
//顶部
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new FlowLayout());
titlePanel.add(new JLabel("系统管理员登录"));
c.add(titlePanel,"North");
//中部表单
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(null);
JLabel l1 = new JLabel("用户名:");
l1.setBounds(50, 20, 50, 20);
JLabel l2 = new JLabel("密码:");
l2.setBounds(50, 60, 50, 20);
fieldPanel.add(l1);
fieldPanel.add(l2);
username.setBounds(110,20,120,20);
password.setBounds(110,60,120,20);
fieldPanel.add(username);
fieldPanel.add(password);
c.add(fieldPanel,"Center");
//底部按钮
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(ok);
buttonPanel.add(cancel);
c.add(buttonPanel,"South");
}
public static void main(String[] args){
new Login();
}
}
求一个用java写的学生成绩管理信息系统的源代码,要求有界面,能实现以下方法实现了用户界面登陆
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用户名:");//使用文本创建一个用户名标签
TextField t1=new TextField();//创建一个文本框对象
Label password=new Label("密码:");//创建一个密码标签
TextField t2=new TextField();
Button b1=new Button("登陆");//创建登陆按钮
Button b2=new Button("取消");//创建取消按钮
public DengLuJieMian()
{
this.setTitle("学生信息管理系统");//设置窗口标题
this.setLayout(null);//设置窗口布局管理器
username.setBounds(50,40,60,20);//设置姓名标签的初始位置
this.add(username);// 将姓名标签组件添加到容器
t1.setBounds(120,40,80,20);// 设置文本框的初始位置
this.add(t1);// 将文本框组件添加到容器
password.setBounds(50,100,60,20);//密码标签的初始位置
this.add(password);//将密码标签组件添加到容器
t2.setBounds(120,100,80,20);//设置密码标签的初始位置
this.add(t2);//将密码标签组件添加到容器
b1.setBounds(50,150,60,20);//设置登陆按钮的初始位置
this.add(b1);//将登陆按钮组件添加到容器
b2.setBounds(120,150,60,20);//设置取消按钮的初始位置
this.add(b2);// 将取消按钮组件添加到容器
b1.addActionListener(this);//给登陆按钮添加监听器
b2.addActionListener(this);// 给取消按钮添加监听器
this.setVisible(true);//设置窗口的可见性
this.setSize(300,200);//设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通过内部类重写关闭窗体的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//处理登陆事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=nullpass.equals("000123"))//判断语句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函数
{
new DengLuJieMian();
}
}
以下方法实现了学生界面设计
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//创建菜单栏
Menu m1=new Menu("信息");//创建菜单“信息”
MenuItem m11=new MenuItem("插入");//创建“插入”的菜单项
MenuItem m12=new MenuItem("查询");
Menu m2=new Menu("成绩");//创建菜单“成绩”
MenuItem m21=new MenuItem("查询");
public StudentJieMian()
{
this.setTitle("学生界面");//设置窗口标题
this.setLayout(new CardLayout());//设置窗口布局管理器
this.setMenuBar(m);//将菜单栏组件添加到容器
m.add(m1);//将信息菜单放入菜单栏
m.add(m2);
m1.add(m11);//将“插入”菜单项添加到“信息”菜单
m1.add(m12); //将“查询”菜单项添加到“信息”菜单
m2.add(m21); //将“查询”菜单项添加到“成绩”菜单
m11.addActionListener(this); //给“插入”菜单项添加监听器
m12.addActionListener(this); //给“查询”菜单项添加监听器
m21.addActionListener(this); //给“查询”菜单项添加监听器
this.setVisible(true); //设置窗口的可见性
this.setSize(300,200); //设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//关闭窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11)//处理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12)//处理“查询信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21)//处理“查询成绩”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{new StudentJieMian();//创建一个对象}
关于java添加界面源代码和java编写界面的代码的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 群晖搭建文件网站,群晖搭建个人web网站
- 蓝桥杯C语言程序,蓝桥杯c语言程序填空题
- 登游戏网络环境存在风险,登游戏网络环境存在风险怎么办
- 虎牙坐骑在哪看直播,虎牙直播坐骑在哪里
- 包含vb.net公式函数的词条
- java警告框代码,java错误提示框
- 公众号logo怎么弄,公众号的logo怎么弄上去
- 1912桃子直播录屏的简单介绍
- go语言微盘 go语言入门经典pdf网盘