java动力代码,能源与动力工程的代码-成都快上网建站

java动力代码,能源与动力工程的代码

Java实验,代码怎么写?

Shape.java接口代码

10多年专注建站、设计、互联网产品按需规划网站服务,业务涵盖成都品牌网站建设购物商城网站建设小程序设计、软件系统开发、重庆APP软件开发等。凭借多年丰富的经验,我们会仔细了解每个客户的需求而做出多方面的分析、设计、整合,为客户设计出具风格及创意性的商业解决方案,创新互联更提供一系列网站制作和网站推广的服务,以推动各中小企业全面信息数字化,并利用创新技术帮助各行业提升企业形象和运营效率。

public interface Shape {

public static final double PI = 3.14d;

public double area();

}

Circle.java圆类代码

public class Circle implements Shape {

private double radius;

public Circle(double radius) {

  this.radius = radius;

}

@Override

public double area() {

  return PI * this.radius * this.radius;

}

public double perimeter() {

  return 2 * PI * this.radius;

}

}

Cylinder.java圆柱体类代码

public class Cylinder extends Circle {

private double height;

public Cylinder(double radius, double height) {

  super(radius);

  this.height = height;

}

public double area() {

  return 2 * super.area() + super.perimeter() * this.height;

}

public double volume() {

  return super.area() * this.height;

}

}

X5_3_6.java主类代码

public class X5_3_6 {

public static void main(String[] args) {

  Circle cir1 = new Circle(5);

  System.out.println("圆的面积为:" + cir1.area());

  System.out.println("圆的周长为:" + cir1.perimeter());

  Cylinder cy1 = new Cylinder(10, 15);

  System.out.println("圆柱体的表面积为:" + cy1.area());

  System.out.println("圆柱体的体积为:" + cy1.volume());

}

}

上面是我写的代码,下图是执行结果,麻烦看一下,是否可以。

求一段java代码,运行时可调用浏览器打开一个网页,网页地址在代码中即可

package com.test;

import java.lang.reflect.Method;

//实现打开浏览器并跳到指定网址的类

public class BareBonesBrowserLaunch {

public static void openURL(String url) {

try {

browse(url);

} catch (Exception e) {

}

}

private static void browse(String url) throws Exception {

//获取操作系统的名字

String osName = System.getProperty("os.name", "");

if (osName.startsWith("Mac OS")) {

//苹果的打开方式

Class fileMgr = Class.forName("com.apple.eio.FileManager");

Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });

openURL.invoke(null, new Object[] { url });

} else if (osName.startsWith("Windows")) {

//windows的打开方式。

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);

} else {

// Unix or Linux的打开方式

String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };

String browser = null;

for (int count = 0; count browsers.length browser == null; count++)

//执行代码,在brower有值后跳出,

//这里是如果进程创建成功了,==0是表示正常结束。

if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)

browser = browsers[count];

if (browser == null)

throw new Exception("Could not find web browser");

else

//这个值在上面已经成功的得到了一个进程。

Runtime.getRuntime().exec(new String[] { browser, url });

}

}

}

//主方法 测试类

public static void main(String[] args) {

String url = "";

BareBonesBrowserLaunch.openURL(url);

}

朋友,觉得好的话,请采纳!你的鼓励是我学习的动力。

JAVA代码

连连看java源代码

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组

JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮

JLabel fractionLable=new JLabel("0"); //分数标签

JButton firstButton,secondButton; //分别记录两次被选中的按钮

int grid[][] = new int[8][7];//储存游戏按钮位置

static boolean pressInformation=false; //判断是否有按钮被选中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标

int i,j,k,n;//消除方法控制

public void init(){

mainFrame=new JFrame("JKJ连连看");

thisContainer = mainFrame.getContentPane();

thisContainer.setLayout(new BorderLayout());

centerPanel=new JPanel();

southPanel=new JPanel();

northPanel=new JPanel();

thisContainer.add(centerPanel,"Center");

thisContainer.add(southPanel,"South");

thisContainer.add(northPanel,"North");

centerPanel.setLayout(new GridLayout(6,5));

for(int cols = 0;cols 6;cols++){

for(int rows = 0;rows 5;rows++ ){

diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

}

}

exitButton=new JButton("退出");

exitButton.addActionListener(this);

resetButton=new JButton("重列");

resetButton.addActionListener(this);

newlyButton=new JButton("再来一局");

newlyButton.addActionListener(this);

southPanel.add(exitButton);

southPanel.add(resetButton);

southPanel.add(newlyButton);

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));

northPanel.add(fractionLable);

mainFrame.setBounds(280,100,500,450);

mainFrame.setVisible(true);

}

public void randomBuild() {

int randoms,cols,rows;

for(int twins=1;twins=15;twins++) {

randoms=(int)(Math.random()*25+1);

for(int alike=1;alike=2;alike++) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

}

this.grid[cols][rows]=randoms;

}

}

}

public void fraction(){

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));

}

public void reload() {

int save[] = new int[30];

int n=0,cols,rows;

int grid[][]= new int[8][7];

for(int i=0;i=6;i++) {

for(int j=0;j=5;j++) {

if(this.grid[i][j]!=0) {

save[n]=this.grid[i][j];

n++;

}

}

}

n=n-1;

this.grid=grid;

while(n=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

}

this.grid[cols][rows]=save[n];

n--;

}

mainFrame.setVisible(false);

pressInformation=false; //这里一定要将按钮点击信息归为初始

init();

for(int i = 0;i 6;i++){

for(int j = 0;j 5;j++ ){

if(grid[i+1][j+1]==0)

diamondsButton[i][j].setVisible(false);

}

}

}

public void estimateEven(int placeX,int placeY,JButton bz) {

if(pressInformation==false) {

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

pressInformation=true;

}

else {

x0=x;

y0=y;

fristMsg=secondMsg;

firstButton=secondButton;

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

if(fristMsg==secondMsg secondButton!=firstButton){

xiao();

}

}

}

public void xiao() { //相同的情况下能不能消去。仔细分析,不一条条注释

if((x0==x (y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)(y0==y))){ //判断是否相邻

remove();

}

else{

for (j=0;j7;j++ ) {

if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空

if (yj) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边

for (i=y-1;i=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0) {

k=0;

break;

}

else //K=1说明通过了第一次验证

}

if (k==1) {

linePassOne();

}

}

if (yj){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边

for (i=y+1;i=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0){

k=0;

break;

}

else

}

if (k==1){

linePassOne();

}

}

if (y==j ) {

linePassOne();

}

}

if (k==2) {

if (x0==x) {

remove();

}

if (x0x) {

for (n=x0;n=x-1;n++ ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 n==x-1) {

remove();

}

}

}

if (x0x) {

for (n=x0;n=x+1 ;n-- ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 n==x+1) {

remove();

}

}

}

}

}

for (i=0;i8;i++ ) { //列

if (grid[i][y0]==0) {

if (xi) {

for (j=x-1;j=i ;j-- ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else

}

if (k==1) {

rowPassOne();

}

}

if (xi) {

for (j=x+1;j=i;j++ ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else

}

if (k==1) {

rowPassOne();

}

}

if (x==i) {

rowPassOne();

}

}

if (k==2){

if (y0==y) {

remove();

}

if (y0y) {

for (n=y0;n=y-1 ;n++ ) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 n==y-1) {

remove();

}

}

}

if (y0y) {

for (n=y0;n=y+1 ;n--) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 n==y+1) {

remove();

}

}

}

}

}

}

}

public void linePassOne(){

if (y0j){ //第一按钮同行空按钮在左边

for (i=y0-1;i=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮

if (grid[x0][i]!=0) {

k=0;

break;

}

else //K=2说明通过了第二次验证

}

}

if (y0j){ //第一按钮同行空按钮在与第二按钮之间

for (i=y0+1;i=j ;i++){

if (grid[x0][i]!=0) {

k=0;

break;

}

else

}

}

}

public void rowPassOne(){

if (x0i) {

for (j=x0-1;j=i ;j-- ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else

}

}

if (x0i) {

for (j=x0+1;j=i ;j++ ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else

}

}

}

public void remove(){

firstButton.setVisible(false);

secondButton.setVisible(false);

fraction();

pressInformation=false;

k=0;

grid[x0][y0]=0;

grid[x][y]=0;

}

public void actionPerformed(ActionEvent e) {

if(e.getSource()==newlyButton){

int grid[][] = new int[8][7];

this.grid = grid;

randomBuild();

mainFrame.setVisible(false);

pressInformation=false;

init();

}

if(e.getSource()==exitButton)

System.exit(0);

if(e.getSource()==resetButton)

reload();

for(int cols = 0;cols 6;cols++){

for(int rows = 0;rows 5;rows++ ){

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);

}

}

}

public static void main(String[] args) {

lianliankan llk = new lianliankan();

llk.randomBuild();

llk.init();

}

}

//old 998 lines

//new 318 lines

java代码详细注释

public class ChatUDPJFrame extends JFrame implements ActionListener {

private String name; // 网名

private InetAddress destip; // 目标主机名或IP地址

private int destport; // 目标主机的端口号

private JTextArea text_receiver; // 显示对话内容的文本区

private JTextField text_sender; // 输入发送内容的文本行

public ChatUDPJFrame(String name, String host, int destport, int receiveport)

throws Exception {

super("聊天室 " + name + " " + InetAddress.getLocalHost() + " : "

+ receiveport);

this.setBounds(320, 240, 400, 240);//设置ChatUDPJFrame新的位置

this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置用户在ChatUDPJFrame窗体上发起 "close" 时默认执行的操作:退出程序

this.text_receiver = new JTextArea();//将text_receiver事例化

this.text_receiver.setEditable(false);//设置text_receiver为不可编辑

this.getContentPane().add(new JScrollPane(this.text_receiver));//把text_receiver添加到一个JScrollPane然后添加到宽框体的面板里

JPanel panel = new JPanel();//实例化了一个panel

this.getContentPane().add(panel, "South");//把panel添加到窗体的南部

this.text_sender = new JTextField(20);//实例化text_sender

panel.add(this.text_sender);//把text_sender添加到panel里

JButton button_send = new JButton("发送");//实例化button_send

panel.add(button_send);//把button_send添加到了panel里

button_send.addActionListener(this);//给button_send添加监听器

this.setVisible(true);//设置窗体可见

this.name = name;//设置ChatUDPJFrame的name

this.destip = InetAddress.getByName(host);//给ChatUDPJFrame的destip复制

this.destport = destport;//给ChatUDPJFrame的destport赋值

byte data[] = new byte[512]; // 以下接收数据报包并显示

DatagramPacket pack = new DatagramPacket(data, data.length); // 创建待接收数据报包

DatagramSocket socket = new DatagramSocket(receiveport); // 创建待接收Socket

while (socket != null) {

socket.receive(pack); // 接收数据报包

int length = pack.getLength(); // 获得包长度

String message = new String(pack.getData(), 0, length);// 获得包中字节数据并转成字符串

text_receiver.append(message + "\r\n");//text_receiver追加内容message

}

}

public void actionPerformed(ActionEvent e) {

if (e.getActionCommand() == "发送") {//如果按的是放松按钮

byte buffer[] = (name + " 说:" + text_sender.getText()).getBytes(); // 将字符串转换成字节

try {

DatagramPacket pack = new DatagramPacket(buffer, buffer.length,

destip, destport);//实例化一个DatagramPacket 名为pack

new DatagramSocket().send(pack); // 绑定一个可用端口发送数据报

} catch (Exception ex) {

ex.printStackTrace();

}

text_receiver.append("我说:" + text_sender.getText() + "\n");//text_receiver的内容后面追加text_sender的内容,然后

text_sender.setText("");//将text_sender的文本内容清空

}

}

public static void main(String args[]) throws Exception {

new ChatUDPJFrame("玉公主", "127.0.0.1", 3001, 3002);//实例化了一个ChatUDPJFrame

}

}

求JAVA视频播放器代码

import java.awt.BorderLayout;

import java.awt.Component;

import java.awt.FileDialog;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.media.ControllerClosedEvent;

import javax.media.ControllerEvent;

import javax.media.ControllerListener;

import javax.media.EndOfMediaEvent;

import javax.media.Manager;

import javax.media.MediaLocator;

import javax.media.NoPlayerException;

import javax.media.Player;

import javax.media.PrefetchCompleteEvent;

import javax.media.RealizeCompleteEvent;

import javax.media.Time;

import javax.swing.JCheckBoxMenuItem;

import javax.swing.JFrame;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

public class JMFMediaPlayer extends JFrame implements ActionListener,

ControllerListener, ItemListener {

// JMF的播放器

Player player;

// 播放器的视频组件和控制组件

Component vedioComponent;

Component controlComponent;

// 标示是否是第一次打开播放器

boolean first = true;

// 标示是否需要循环

boolean loop = false;

// 文件当前目录

String currentDirectory;

// 构造方法

public JMFMediaPlayer(String title) {

super(title);

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e){

// 用户点击窗口系统菜单的关闭按钮

// 调用dispose以执行windowClosed

dispose();

}

public void windowClosed(WindowEvent e){

if (player != null){

// 关闭JMF播放器对象

player.close();

}

System.exit(0);

}

});

// 创建播放器的菜单

JMenu fileMenu = new JMenu("文件");

JMenuItem openMemuItem = new JMenuItem("打开");

openMemuItem.addActionListener(this);

fileMenu.add(openMemuItem);

// 添加一个分割条

fileMenu.addSeparator();

// 创建一个复选框菜单项

JCheckBoxMenuItem loopMenuItem = new JCheckBoxMenuItem("循环", false);

loopMenuItem.addItemListener(this);

fileMenu.add(loopMenuItem);

fileMenu.addSeparator();

JMenuItem exitMemuItem = new JMenuItem("退出");

exitMemuItem.addActionListener(this);

fileMenu.add(exitMemuItem);

JMenuBar menuBar = new JMenuBar();

menuBar.add(fileMenu);

this.setJMenuBar(menuBar);

this.setSize(200, 200);

try {

// 设置界面的外观,为系统外观

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

SwingUtilities.updateComponentTreeUI(this);

} catch (Exception e) {

e.printStackTrace();

}

this.setVisible(true);

}

/**

* 实现了ActionListener接口,处理组件的活动事件

*/

public void actionPerformed(ActionEvent e) {

if (e.getActionCommand().equals("退出")) {

// 调用dispose以便执行windowClosed

dispose();

return;

}

FileDialog fileDialog = new FileDialog(this, "打开媒体文件", FileDialog.LOAD);

fileDialog.setDirectory(currentDirectory);

fileDialog.setVisible(true);

// 如果用户放弃选择文件,则返回

if (fileDialog.getFile() == null){

return;

}

currentDirectory = fileDialog.getDirectory();

if (player != null){

// 关闭已经存在JMF播放器对象

player.close();

}

try {

// 创建一个打开选择文件的播放器

player = Manager.createPlayer(new MediaLocator("file:"

+ fileDialog.getDirectory() + fileDialog.getFile()));

} catch (java.io.IOException e2) {

System.out.println(e2);

return;

} catch (NoPlayerException e2) {

System.out.println("不能找到播放器.");

return;

}

if (player == null) {

System.out.println("无法创建播放器.");

return;

}

first = false;

this.setTitle(fileDialog.getFile());

// 播放器的控制事件处理

player.addControllerListener(this);

// 预读文件内容

player.prefetch();

}

/**

* 实现ControllerListener接口的方法,处理播放器的控制事件

*/

public void controllerUpdate(ControllerEvent e) {

// 调用player.close()时ControllerClosedEvent事件出现。

// 如果存在视觉部件,则该部件应该拆除(为一致起见,

// 我们对控制面板部件也执行同样的操作)

if (e instanceof ControllerClosedEvent) {

if (vedioComponent != null) {

this.getContentPane().remove(vedioComponent);

this.vedioComponent = null;

}

if (controlComponent != null) {

this.getContentPane().remove(controlComponent);

this.controlComponent = null;

}

return;

}

// 如果是媒体文件到达尾部事件

if (e instanceof EndOfMediaEvent) {

if (loop) {

// 如果允许循环,则重新开始播放

player.setMediaTime(new Time(0));

player.start();

}

return;

}

// 如果是播放器预读事件

if (e instanceof PrefetchCompleteEvent) {

// 启动播放器

player.start();

return;

}

// 如果是文件打开完全事件,则显示视频组件和控制器组件

if (e instanceof RealizeCompleteEvent) {

vedioComponent = player.getVisualComponent();

if (vedioComponent != null){

this.getContentPane().add(vedioComponent);

}

controlComponent = player.getControlPanelComponent();

if (controlComponent != null){

this.getContentPane().add(controlComponent, BorderLayout.SOUTH);

}

this.pack();

}

}

// 处理“循环”复选框菜单项的点击事件

public void itemStateChanged(ItemEvent e) {

loop = !loop;

}

public static void main(String[] args){

new JMFMediaPlayer("JMF媒体播放器");

}

}

试试吧,我这里运行正常

求代码:java文件操作

加了点注释。实现方式和楼上差不多。

仔细看看。

package cn.com.storm.common.test;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

public class Test {

// 开始字符串

private final static String START_STRING = "startPosition";

// 结束字符串

private final static String END_STRING = "/startPosition";

public static void main(String[] args) {

File oldFile = new File("d:\\xxx.xrdml");

BufferedReader br = null;

BufferedWriter bw = null;

try {

// 获得原文件的输入流

br = new BufferedReader(new InputStreamReader(new FileInputStream(oldFile)));

// 获得新文件的输出流

bw =new BufferedWriter(new OutputStreamWriter(new FileOutputStream(oldFile.getParent()

+ oldFile.getName().replace(".", "_2."))));

// 读取一行记录

String line = null;

while ((line = br.readLine()) != null) {

// 判断当前行是否包含startPosition与/startPosition

if (line.contains(START_STRING) line.contains(END_STRING)) {

// 获取startPosition与/startPosition中间的字符串

String strNum = line.substring(line.indexOf(START_STRING) + START_STRING.length(),

line.indexOf(END_STRING));

// 转化成double类型

double num = Double.parseDouble(strNum);

num = num / 2;

// 把原数字替换成新数字

line.replace(strNum, String.valueOf(num));

}

// 写入新文件一行数据

bw.write(line);

// 写入新文件换行符

bw.newLine();

}

} catch (FileNotFoundException e) {

System.out.println("文件不存在!");

} catch (NumberFormatException e) {

System.out.println("文件中的数据错误!");

} catch (IOException e) {

System.out.println("文件读取或写入时发生错误!");

} finally {

if (br != null) {

try {

br.close();

} catch (IOException e) {

System.out.println("文件关闭失败");

}

}

if (bw != null) {

try {

bw.close();

} catch (IOException e) {

System.out.println("文件关闭失败");

}

}

}

}

}


当前标题:java动力代码,能源与动力工程的代码
文章来源:http://kswjz.com/article/dssschs.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流