高分悬赏求一JAVA小程序!!在线等!!!
如题,小程序要简单易懂,程序写完后最好再说明一下原理和操作流程,如果写的好的再追加高分!!!!!...
如题,小程序要简单易懂,程序写完后最好再说明一下原理和操作流程,如果写的好的再追加高分!!!!!
展开
5个回答
展开全部
/*
* 这个程序实现输入身高算出标准体重,输入体重,算出身高的功能
*/
import java.awt.*; //导入相关类包,这才样使用相应awt图形界面的类
import java.awt.event.*;//同上
public class Change extends Frame { //定义一个类Change, 父类是Frame(图形界面的)
Button b = new Button("互查"); //创建一个按钮的对象b,显示为"互查"
Label l1 = new Label("身高(cm)");//创建一个lable.显示身高
Label l2 = new Label("体重(kg)");//创建一个lable 显示体重
double heigth, weigth; //定义变量
double x, y; //定义变量
TextField tf1 = new TextField(null, 10);//添加Text框
TextField tf2 = new TextField(null, 10);//添加Text框
public Change() {//类的构造函数,完成初始化
super("互查表");//创建窗口,标题为互查表
setLayout(new FlowLayout(FlowLayout.LEFT));//设置布局
add(l1);//把lable 身高放到window里
add(tf1);//把Text 框 放到窗口上
add(l2); //把lable 体重放到window里
add(tf2);//Test放到窗口里
add(b);//把button放到窗口上
pack();//自动放到窗口里排列上边的组件
setVisible(true);//可以让用户看到窗口
addWindowListener(new WindowAdapter() {//如果按 X, 关闭窗口
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());//添加button监听函数
}
class ButtonListener implements ActionListener {//实现click button时功能操作
public void actionPerformed(ActionEvent e) {//当click调用
if (tf1.getText()!=null) {//检查tf1 test 是否为空
try {//取异常
x = Double.parseDouble(tf1.getText());//字符转为double型
weigth = (x - 100) * 0.9;//算重量
tf2.setText("" + weigth);//显示重量
} catch (NumberFormatException ex) {
tf1.setText("");//如果输入不是数字,设为空
}
}
if (tf1.getText().equals("")==true){//tf1是否为空
y = Double.parseDouble(tf2.getText());//把tf2里的文本转为double 型 的
heigth = y / 0.9 + 100; //算身高根据重量
tf1.setText("" + heigth);}//显示身高
}
}
public static void main(String[] args) {//主函数,程序入口
new Change(); //建立类Change的对象,并调用他的构造函数Change().显示窗口
}
}
* 这个程序实现输入身高算出标准体重,输入体重,算出身高的功能
*/
import java.awt.*; //导入相关类包,这才样使用相应awt图形界面的类
import java.awt.event.*;//同上
public class Change extends Frame { //定义一个类Change, 父类是Frame(图形界面的)
Button b = new Button("互查"); //创建一个按钮的对象b,显示为"互查"
Label l1 = new Label("身高(cm)");//创建一个lable.显示身高
Label l2 = new Label("体重(kg)");//创建一个lable 显示体重
double heigth, weigth; //定义变量
double x, y; //定义变量
TextField tf1 = new TextField(null, 10);//添加Text框
TextField tf2 = new TextField(null, 10);//添加Text框
public Change() {//类的构造函数,完成初始化
super("互查表");//创建窗口,标题为互查表
setLayout(new FlowLayout(FlowLayout.LEFT));//设置布局
add(l1);//把lable 身高放到window里
add(tf1);//把Text 框 放到窗口上
add(l2); //把lable 体重放到window里
add(tf2);//Test放到窗口里
add(b);//把button放到窗口上
pack();//自动放到窗口里排列上边的组件
setVisible(true);//可以让用户看到窗口
addWindowListener(new WindowAdapter() {//如果按 X, 关闭窗口
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());//添加button监听函数
}
class ButtonListener implements ActionListener {//实现click button时功能操作
public void actionPerformed(ActionEvent e) {//当click调用
if (tf1.getText()!=null) {//检查tf1 test 是否为空
try {//取异常
x = Double.parseDouble(tf1.getText());//字符转为double型
weigth = (x - 100) * 0.9;//算重量
tf2.setText("" + weigth);//显示重量
} catch (NumberFormatException ex) {
tf1.setText("");//如果输入不是数字,设为空
}
}
if (tf1.getText().equals("")==true){//tf1是否为空
y = Double.parseDouble(tf2.getText());//把tf2里的文本转为double 型 的
heigth = y / 0.9 + 100; //算身高根据重量
tf1.setText("" + heigth);}//显示身高
}
}
public static void main(String[] args) {//主函数,程序入口
new Change(); //建立类Change的对象,并调用他的构造函数Change().显示窗口
}
}
展开全部
import java.io.*;
public class ReadFile{
public static void main(String args[])throws Exception{
int b=0;
FileReader in=new FileReader("D://abc.dat");
try{
while((b=in.read())!=-1){
System.out.print((char)b);
}
}catch(Exception ex){
in.close();
}
}
}
public class ReadFile{
public static void main(String args[])throws Exception{
int b=0;
FileReader in=new FileReader("D://abc.dat");
try{
while((b=in.read())!=-1){
System.out.print((char)b);
}
}catch(Exception ex){
in.close();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
顶三楼。简单易懂。不过我觉得我这个合适
public class T
{
public satic void main()
{
int i,j;
i=2;
j=3;
System.out.println("i+j的和="+(i+j));
}
}
public class T
{
public satic void main()
{
int i,j;
i=2;
j=3;
System.out.println("i+j的和="+(i+j));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我写的截图软件,分两个文件,如果难懂或觉得我的好的话hi我,我再给你注释
import java.awt.AWTException;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JWindow;
import javax.swing.UIManager;
public class CacheFrame extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
public static Dimension tk=Toolkit.getDefaultToolkit().getScreenSize();
JButton btn1=new JButton("选定");
JButton btn2=new JButton("截图");
JLabel lab1=new JLabel("X1:");
JLabel lab2=new JLabel("Y1:");
JLabel lab3=new JLabel("延时(S):");
JLabel lab4=new JLabel("X2");
JLabel lab5=new JLabel("Y2");
public static JTextField jtf1=new JTextField("0");
public static JTextField jtf2=new JTextField("0");
JTextField jtf3=new JTextField("2");
public static JTextField jtf4=new JTextField(""+tk.width);
public static JTextField jtf5=new JTextField(""+tk.height);
public static JFrame jframe;
public static JWindow jw;
CacheFrame(){
}
CacheFrame(String title){
setTitle(title);
setLayout(new GridLayout(2,6));
setBounds((tk.width-400)/2,(tk.height-100)/2,400,100);
add(lab1);
add(jtf1);
add(lab2);
add(jtf2);
add(lab3);
add(jtf3);
add(lab4);
add(jtf4);
add(lab5);
add(jtf5);
add(btn1);
add(btn2);
btn2.requestFocus();
jframe=this;
btn1.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e){
jframe.setVisible(false);
String name="buf"+"."+"png";
File f=new File(name);
try {
BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(0,0,CacheFrame.tk.width,CacheFrame.tk.height));
// BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(10,10,100,100));
ImageIO.write(bImage,"png",f);
} catch (AWTException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
jw=new JWindow();
jw.setBounds(0, 0, tk.width,tk.height);
JPanel jp=new newPanel();
jw.add(jp);
jw.setVisible(true);
}
});
btn2.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e){
int x1=0,y1=0,x2=0,y2=0,delay=0;
try{
x1=Integer.parseInt(jtf1.getText());
}catch(Exception e1){jtf1.setText("Error!");jtf1.requestFocus();jtf1.setCursor(new Cursor(0));return;}
try{
y1=Integer.parseInt(jtf2.getText());
}catch(Exception e1){jtf2.setText("Error!");jtf2.requestFocus();return;}
try{
x2=Integer.parseInt(jtf4.getText());
}catch(Exception e1){jtf4.setText("Error!");jtf4.requestFocus();return;}
try{
y2=Integer.parseInt(jtf5.getText());
}catch(Exception e1){jtf5.setText("Error!");jtf5.requestFocus();return;}
try{
delay=Integer.parseInt(jtf3.getText());
}catch(Exception e1){jtf3.setText("Error!");jtf3.requestFocus();return;}
if(delay<0)
delay=0;
try{
Thread.sleep(delay*1000);
BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(x1,y1,x2-x1,y2-y1));
// BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(10,10,100,100));
String name="su"+"."+"png";
File f=new File(name);
ImageIO.write(bImage,"png",f);
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[]){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e1) {
e1.printStackTrace();
}
new CacheFrame("截图软件");
}
}
import java.awt.AlphaComposite;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class newPanel extends JPanel implements MouseListener,MouseMotionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
private float alpha = 0.8f;
private int x1=0;
private int y1=0;
private int x2=0;
private int y2=0;
public int xx1=0;
public int yy1=0;
public int xx2=0;
public int yy2=0;
private boolean enable=false;
JLabel jl=new JLabel();
Graphics2D g2d;
public newPanel() {
this.add(jl);
jl.setIcon(new ImageIcon("buf.png"));
Thread thread = new Thread() {
public void run() {
while (true) {
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
};
thread.start();
jl.addMouseListener(this);
jl.addMouseMotionListener(this);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
alpha);
g2d.setComposite(ac);
Font font = new Font("tahoma", Font.BOLD, 15);
g2d.setFont(font);
g2d.drawString("x1:"+x1+"y1:"+y1, x1, y1);
g2d.drawString("x2:"+x2+"y2:"+y2, x2, y2);
if(enable)
{
if(x1>x2){
xx1=x2;
xx2=x1;
}
else{
xx1=x1;
xx2=x2;
}
if(y1>y2){
yy1=y2;
yy2=y1;
}else{
yy1=y1;
yy2=y2;
}
}
g2d.drawRect(xx1, yy1, xx2-xx1, yy2-yy1);
}
public void mouseDragged(MouseEvent e) {
x2=e.getX();
y2=e.getY();
enable=true;
}
public void mouseMoved(MouseEvent e) {
x1=e.getX();
y1=e.getY();
if(enable)
enable=false;
}
public void mouseClicked(MouseEvent arg0) {
CacheFrame.jw.dispose();
CacheFrame.jframe.setVisible(true);
CacheFrame.jtf1.setText(""+xx1);
CacheFrame.jtf2.setText(""+yy1);
CacheFrame.jtf4.setText(""+xx2);
CacheFrame.jtf5.setText(""+yy2);
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
import java.awt.AWTException;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JWindow;
import javax.swing.UIManager;
public class CacheFrame extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
public static Dimension tk=Toolkit.getDefaultToolkit().getScreenSize();
JButton btn1=new JButton("选定");
JButton btn2=new JButton("截图");
JLabel lab1=new JLabel("X1:");
JLabel lab2=new JLabel("Y1:");
JLabel lab3=new JLabel("延时(S):");
JLabel lab4=new JLabel("X2");
JLabel lab5=new JLabel("Y2");
public static JTextField jtf1=new JTextField("0");
public static JTextField jtf2=new JTextField("0");
JTextField jtf3=new JTextField("2");
public static JTextField jtf4=new JTextField(""+tk.width);
public static JTextField jtf5=new JTextField(""+tk.height);
public static JFrame jframe;
public static JWindow jw;
CacheFrame(){
}
CacheFrame(String title){
setTitle(title);
setLayout(new GridLayout(2,6));
setBounds((tk.width-400)/2,(tk.height-100)/2,400,100);
add(lab1);
add(jtf1);
add(lab2);
add(jtf2);
add(lab3);
add(jtf3);
add(lab4);
add(jtf4);
add(lab5);
add(jtf5);
add(btn1);
add(btn2);
btn2.requestFocus();
jframe=this;
btn1.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e){
jframe.setVisible(false);
String name="buf"+"."+"png";
File f=new File(name);
try {
BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(0,0,CacheFrame.tk.width,CacheFrame.tk.height));
// BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(10,10,100,100));
ImageIO.write(bImage,"png",f);
} catch (AWTException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
jw=new JWindow();
jw.setBounds(0, 0, tk.width,tk.height);
JPanel jp=new newPanel();
jw.add(jp);
jw.setVisible(true);
}
});
btn2.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e){
int x1=0,y1=0,x2=0,y2=0,delay=0;
try{
x1=Integer.parseInt(jtf1.getText());
}catch(Exception e1){jtf1.setText("Error!");jtf1.requestFocus();jtf1.setCursor(new Cursor(0));return;}
try{
y1=Integer.parseInt(jtf2.getText());
}catch(Exception e1){jtf2.setText("Error!");jtf2.requestFocus();return;}
try{
x2=Integer.parseInt(jtf4.getText());
}catch(Exception e1){jtf4.setText("Error!");jtf4.requestFocus();return;}
try{
y2=Integer.parseInt(jtf5.getText());
}catch(Exception e1){jtf5.setText("Error!");jtf5.requestFocus();return;}
try{
delay=Integer.parseInt(jtf3.getText());
}catch(Exception e1){jtf3.setText("Error!");jtf3.requestFocus();return;}
if(delay<0)
delay=0;
try{
Thread.sleep(delay*1000);
BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(x1,y1,x2-x1,y2-y1));
// BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(10,10,100,100));
String name="su"+"."+"png";
File f=new File(name);
ImageIO.write(bImage,"png",f);
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[]){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e1) {
e1.printStackTrace();
}
new CacheFrame("截图软件");
}
}
import java.awt.AlphaComposite;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class newPanel extends JPanel implements MouseListener,MouseMotionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
private float alpha = 0.8f;
private int x1=0;
private int y1=0;
private int x2=0;
private int y2=0;
public int xx1=0;
public int yy1=0;
public int xx2=0;
public int yy2=0;
private boolean enable=false;
JLabel jl=new JLabel();
Graphics2D g2d;
public newPanel() {
this.add(jl);
jl.setIcon(new ImageIcon("buf.png"));
Thread thread = new Thread() {
public void run() {
while (true) {
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
};
thread.start();
jl.addMouseListener(this);
jl.addMouseMotionListener(this);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
alpha);
g2d.setComposite(ac);
Font font = new Font("tahoma", Font.BOLD, 15);
g2d.setFont(font);
g2d.drawString("x1:"+x1+"y1:"+y1, x1, y1);
g2d.drawString("x2:"+x2+"y2:"+y2, x2, y2);
if(enable)
{
if(x1>x2){
xx1=x2;
xx2=x1;
}
else{
xx1=x1;
xx2=x2;
}
if(y1>y2){
yy1=y2;
yy2=y1;
}else{
yy1=y1;
yy2=y2;
}
}
g2d.drawRect(xx1, yy1, xx2-xx1, yy2-yy1);
}
public void mouseDragged(MouseEvent e) {
x2=e.getX();
y2=e.getY();
enable=true;
}
public void mouseMoved(MouseEvent e) {
x1=e.getX();
y1=e.getY();
if(enable)
enable=false;
}
public void mouseClicked(MouseEvent arg0) {
CacheFrame.jw.dispose();
CacheFrame.jframe.setVisible(true);
CacheFrame.jtf1.setText(""+xx1);
CacheFrame.jtf2.setText(""+yy1);
CacheFrame.jtf4.setText(""+xx2);
CacheFrame.jtf5.setText(""+yy2);
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class T{
public satic void main(){
System.out.print("Holle!");
}
}
这个程序简单易懂。
public satic void main(){
System.out.print("Holle!");
}
}
这个程序简单易懂。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询