java编程

java编程~

如果你要的话、我可以发我的简单学生管理系统给你、不过你得给我加分啊、否则不发!你够吝啬了、一分都不给

二维数组计算每行每列的和不难的吧 用for循环哇

这个是要读取文件然后储存到二维数组中,还是 直接就自己给出二维数组的值~


读文件的话 就是多几个步骤 自己赋值的话 就太简单啦~

祝你好运~

参考链接:http://zhidao.baidu.com/question/46257655.html ;
http://zhidao.baidu.com/question/121171564.html?qbl=relate_question_4 ;


http://zhidao.baidu.com/question/56871292.html ;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;

public class Calucator extends JFrame {

private JTextField tf;
private JPanel panel1, panel2, panel3, panel4;
private JMenuBar myBar;
private JMenu menu1, menu2, menu3;
private JMenuItem editItem1, editItem2, help1, help2, help3;
private JRadioButtonMenuItem seeItem1, seeItem2;
private JCheckBoxMenuItem seeItem3;
private ButtonGroup bgb;
private String back;
private boolean IfResult = true, falg = false;
private String oper = "=";
private double result = 0;
private Num numActionListener;
private DecimalFormat df;

public Calucator(){
super("计算器");

df = new DecimalFormat("0.#######");

this.setLayout(new BorderLayout(10, 5));
panel1 = new JPanel(new GridLayout(1, 3, 10, 10));
panel2 = new JPanel(new GridLayout(4, 5, 5, 5));
panel3 = new JPanel(new GridLayout(5, 1, 5, 5));
panel4 = new JPanel(new BorderLayout(5, 5));

myBar = new JMenuBar();
menu1 = new JMenu("编辑");
menu2 = new JMenu("查看");
menu3 = new JMenu("帮助");

menu1.setFont(new Font("宋体", Font.PLAIN, 12));
menu2.setFont(new Font("宋体", Font.PLAIN, 12));
menu3.setFont(new Font("宋体", Font.PLAIN, 12));

editItem1 = new JMenuItem("复制");
editItem2 = new JMenuItem("粘贴");

seeItem1 = new JRadioButtonMenuItem("科学型");
seeItem2 = new JRadioButtonMenuItem("标准型");
seeItem3 = new JCheckBoxMenuItem("数字分组");

help1 = new JMenuItem("帮助主题");
help2 = new JMenuItem("关于计算器(A)");

bgb = new ButtonGroup();

menu1.add(editItem1);
menu1.add(editItem2);

menu2.add(seeItem1);
menu2.add(seeItem2);
menu2.addSeparator();
menu2.add(seeItem3);

menu3.add(help1);
menu3.add(help2);

myBar.add(menu1);
myBar.add(menu2);
myBar.add(menu3);
this.setJMenuBar(myBar);

numActionListener = new Num();

tf = new JTextField();
tf.setEditable(false);
tf.setBackground(Color.white);
tf.setHorizontalAlignment(JTextField.RIGHT);
tf.setText("0");
tf.setBorder(BorderFactory.createLoweredBevelBorder());
init();

}

private void init(){

addButton(panel1, "Backspace", new Clear(), Color.red);
addButton(panel1, "CE", null, Color.red);
addButton(panel1, "C", new Clear(), Color.red);

addButton(panel2, "7", numActionListener, Color.blue);
addButton(panel2, "8", numActionListener, Color.blue);
addButton(panel2, "9", numActionListener, Color.blue);
addButton(panel2, "/", new Signs(), Color.red);
addButton(panel2, "sqrt", new Signs(), Color.blue);

addButton(panel2, "4", numActionListener, Color.blue);
addButton(panel2, "5", numActionListener, Color.blue);
addButton(panel2, "6", numActionListener, Color.blue);
addButton(panel2, "*", new Signs(), Color.red);
addButton(panel2, "%", new Signs(), Color.blue);

addButton(panel2, "1", numActionListener, Color.blue);
addButton(panel2, "2", numActionListener, Color.blue);
addButton(panel2, "3", numActionListener, Color.blue);
addButton(panel2, "-", new Signs(), Color.red);
addButton(panel2, "1/x", new Signs(), Color.blue);

addButton(panel2, "0", numActionListener, Color.blue);
addButton(panel2, "-/+", new Clear(), Color.blue);
addButton(panel2, ".", new Dot(), Color.blue);
addButton(panel2, "+", new Signs(), Color.red);
addButton(panel2, "=", new Signs(), Color.red);

JButton btns = new JButton("calucator");
btns.setBorder(BorderFactory.createLoweredBevelBorder());
btns.setEnabled(false);
btns.setPreferredSize(new Dimension(20, 20));

panel3.add(btns);
addButton(panel3, "MC", null, Color.red);
addButton(panel3, "MR", null, Color.red);
addButton(panel3, "MS", null, Color.red);
addButton(panel3, "M+", null, Color.red);

panel4.add(panel1, BorderLayout.NORTH);
panel4.add(panel2, BorderLayout.CENTER);
this.add(tf, BorderLayout.NORTH);
this.add(panel3, BorderLayout.WEST);
this.add(panel4);

pack();
this.setResizable(false);
this.setLocation(300, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

private void addButton(JPanel panel, String name, ActionListener action, Color color){
JButton bt = new JButton(name);
panel.add(bt);
bt.setForeground(color);
bt.addActionListener(action);
}

public static void main(String[] args) {

new Calucator().setVisible(true);

}

private void getResult (double x){
System.out.println("result"+result+" "+"x"+x);
if(oper == "+"){
result += x;
}else if(oper == "-"){
result -= x;
}else if(oper == "*"){
result *= x;
}else if(oper == "/"){
result /= x;
}else if(oper == "="){
result = x;
}
System.out.println("result"+result+" "+"x"+x);
tf.setText(df.format(result));
System.out.println(df.format(result));
}

class Signs implements ActionListener{

public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if(str.equals("sqrt")){
double i = Double.parseDouble(tf.getText());

if(i>0){
tf.setText(String.valueOf(df.format(Math.sqrt(i))));
}else{
tf.setText("负数不能开平方根");
}

}else if(str.equals("%")){
tf.setText(df.format(Double.parseDouble(tf.getText()) / 100));
}else if(str.equals("1/x")){

if(Double.parseDouble(tf.getText()) == 0){
tf.setText("除数不能为零");
}else{
tf.setText(df.format(1 / Double.parseDouble(tf.getText())));
}

}else{
if(falg){
IfResult = false;
}
if(IfResult){
oper = str;
System.out.println(oper);
}else{
getResult(Double.parseDouble(tf.getText()));
oper = str;
IfResult = true;
}
}
}
}

class Clear implements ActionListener{

public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if(str == "C"){
tf.setText("0");
IfResult = true;
result = 0;
}else if(str == "-/+"){
double i = 0 - Double.parseDouble(tf.getText().trim());
tf.setText(df.format(i));
}else if(str == "Backspace"){
if(Double.parseDouble(tf.getText()) > 0){

if(tf.getText().length() > 1){
tf.setText(tf.getText().substring(0, tf.getText().length() - 1));
}else{
tf.setText("0");
IfResult = true;
}

}else{
if(tf.getText().length() > 2){
tf.setText(tf.getText().substring(0, tf.getText().length() - 1));
}else{
tf.setText("0");
IfResult = true;
}
}
}

}
}

class Num implements ActionListener{

public void actionPerformed(ActionEvent e) {
String srt = e.getActionCommand();
if(IfResult){
tf.setText("");
IfResult = false;
}
tf.setText(tf.getText().trim() + srt);
if(tf.getText().equals("0")){
tf.setText("0");
IfResult = true;
falg = true;
}
}

}

class Dot implements ActionListener{

public void actionPerformed(ActionEvent e) {
IfResult = false;
if(tf.getText().trim().indexOf(".") == -1){
tf.setText(tf.getText() + ".");
}

}

}

}

这个东西学过一星期JAVA的人,20分钟就能作出来。

import java.awt.*;
import java.awt.event.*;
public class Calculator extends WindowAdapter implements ActionListener
{

private double result=0,data1=0,radixPointDepth=1;

private boolean radixPointIndicate=false,resultIndicate=false;

private char prec='+';
private Frame f;//创建窗口
private TextField tf;//创建文本框
private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18;//创建按钮
private Panel p;//创建/面板容器

static public void main(String args[])
{

Calculator cal=new Calculator();//创建构造方法
cal.init();
}

public void init()
{
f=new Frame("牛兴雷的计算器");
p=new Panel();
p.setLayout(new GridLayout(4,4));
tf=new TextField(30);

b1=new Button("7");
b2=new Button("8");
b3=new Button("9");
b4=new Button("+");
b5=new Button("4");
b6=new Button("5");
b7=new Button("6");
b8=new Button("-");
b9=new Button("1");
b10=new Button("2");
b11=new Button("3");
b12=new Button("*");
b13=new Button("0");
b14=new Button(".");
b15=new Button("=");
b16=new Button("/");
b17=new Button("清零");
b18=new Button("退出") ;

f.add(tf,"North");
f.add(p,"Center");
f.add(b17,"East");
f.add(b18,"South");

p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b6);
p.add(b7);
p.add(b8);
p.add(b9);
p.add(b10);
p.add(b11);
p.add(b12);
p.add(b13);
p.add(b14);
p.add(b15);
p.add(b16);
//为按钮添加监听
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
b17.addActionListener(this);
b18.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
f.setVisible(false);
f.dispose();
System.exit(0);
}
});
f.addWindowListener(this);
f.setSize(300,190);
f.setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
String s;
s=e.getActionCommand();

//SWITCH开关
switch(s.charAt(0))
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9'://按数字按钮执行下面语句
if(resultIndicate) //如果敲过等号,直接敲数字,初始化内容
{
result=0;
data1=0;
prec='+';
}
Integer Int1=new Integer(s);

if(radixPointIndicate) //如果敲击过小数点
{
radixPointDepth=radixPointDepth/10;
data1=data1+(Int1.intValue())*radixPointDepth;
}
else
{
data1=data1*10+(Int1.intValue());
}
Double displayNumber=new Double(data1);
tf.setText(displayNumber.toString());
resultIndicate=false;
break;
case '+':
case '-':
case '*':
case '/':
case '='://按运算符,执行下面语句
if(s.charAt(0)!='='&&resultIndicate)

{
prec=s.charAt(0);
resultIndicate=false;
}
else
{
//用SWITCH开关运算出执行了“+、-、*、/”的结果
switch(prec)
{
case '+':
result=result+data1;
break;
case '-':
result=result-data1;
break;
case '*':
result=result*data1;
break;
case '/':
result=result/data1;
break;
}
}

radixPointIndicate=false;
radixPointDepth=1;

displayNumber=new Double(result); //将计算结果显示在文本框内
tf.setText(displayNumber.toString());

//监听是否按了“=”
if(s.charAt(0)!='=') //如果没有敲等号,则敲了+、-、*、/,那么data1清空
{
data1=0;
prec=s.charAt(0);
}
else
{
resultIndicate=true; //resultIndicate只有当敲击了等号,才为true,否则为false
}
break;
case '.':
radixPointIndicate=true;
break;
}
//监听是否按了为“清零”,是则对各数据清零
if(s.equals("清零"))
{
result=0;
data1=0;
radixPointDepth=1;
tf.setText("");
}
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}

Java怎么学习 入门Java编程的指南?
答:学习Java编程的指南如下:1. 学习基本的编程概念和术语:了解编程中常用的概念,例如变量、数据类型、条件语句、循环语句等。可以通过阅读相关书籍或在线教程来学习。2. 安装和配置Java开发环境:下载和安装Java Development Kit(JDK),并配置环境变量。JDK是Java编程所必需的工具。3. 学习Java语法:掌握...

Java:编程语言之王
答:在编程语言的广阔天地中,新语言层出不穷,给老牌语言带来了不小的挑战。然而,在这场激烈的竞争中,有一种语言始终稳坐江山,那就是Java语言。就业前景最好的编程语言Java是2019年就业前景最好的编程语言。它在众多领域都有广泛的应用,是编程语言之王。广泛的应用领域Java在互联网电子商务、金融行业的服务器应...

java是什么类型的编程语言
答:如JavaScript,python)。4. 从运行时数据类型来分,java是一种静态类型语言,或者说是强类型语言,它的数据类型在编译期或者说运行前确定的,在定义变量时需要明确指定它的数据类型,如果不经过强制类型转换,它的类型就不会变。综合来说,java是一门强类型的、面向对象的混合型高级编程语言。

Java学习之路:适合每个人的个性化方案
答:学习Java编程,不仅是一门技术,更是一场个性化的探索之旅。无论你是工学班的学生还是文科背景的朋友,只要用心规划、踏实学习,Java的世界一定会为你敞开大门。制定长期学习计划Java学习不是一蹴而就的。在开始之前,先为自己制定一个长期的学习计划,确保每一步都走得扎实。从基础出发高级编程框架如Struts2、Spr...

Java实现GUI编程基本方法都有那些?
答:其实无论在什么平台下,GUI应用程序的基本开发方法都是相似的。一般都包括下面这样四个步骤:①创建容器 首先要创建一个GUI应用程序,需要创建一个用于容纳所有其它GUI组件元素的载体,Java中称为容器。典型的包括窗口(Window)、框架(Frame/JFrame)、对话框(Dialog/JDialog)、面板(Panel/JPanel)等。只有...

Java编程应该如何学习?
答:在千锋教育,我们认为学习Java编程是一个系统而全面的过程,需要结合理论知识和实践操作。以下是我们推荐的学习路径:更系统全面的学习资料,点击查看首先,建议从Java的基础开始学习。掌握Java的基本语法、数据类型、运算符、流程控制等基础知识是打好编程基础的关键。在千锋教育的Java开发和培训课程中,我们会...

java编程是什么
答:Java是一种可以撰写跨平台应用程序的、面向对象的程序设计语言。简单说,Java就是一种语言,不过是一种针对jvm的语言,Java编译后是字节码,而jvm会把这些字节码解释成机器码,然后做出相应的动作。Java是计算机和我们的沟通语言,计算机可以懂Java这门语言。当然,你学会了Java,你也会这门语言,你就可以...

java如何编程
答:IDL IDL 是一种数据分析和图像化应用程序及编程语言 Java Java是由Sun Microsystems公司于1995年5月推出的Java程序设计语言 JavaScript Javascript是一种由Netscape的LiveScript发展而来的脚本语言 J# Visual J# 是一种工具,供 Java 语言程序员用于构建在 .NET Framework 上运行的应用程序和服务 LISP 一种...

如何自学Java编程
答:如何自学Java编程?Java已经不是陌生的行业了,Java就业前景不错,工资高,很多小伙伴想要学习Java开发,由于种种原因不能通过Java培训进行学习,想要自学Java编程,但是如何系统的自学Java编程呢!1、如何自学Java编程?选定一个方向 首先,我们选择方向的目的是什么?不就是为了找份工作吗?那直接到招聘类...

java软件编程难学吗?
答:Java编程首先对英语要求挺高的,像一些定义语法都是和英语有关的,如果你英语好,理解起来就容易的多。相对来讲,Java算是简单的,如果你有兴趣,不妨先入门,如果入门容易,就证明你具有编程的天分。就拿国内从业比较广泛的Java开发工程师来讲,高中毕业生都可以做。既然高中生都能从事于Java开发,说明...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网