「java实现di」java实现dir和cd

博主:adminadmin 2023-01-05 23:30:12 612

今天给各位分享java实现di的知识,其中也会对java实现dir和cd进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

JAVA设计一个三角形类Trival,其中的属性包括三角形的底di,三角形的高gao?

public class Trival

public void setDi(float di) {

this.di = di;

public void setGao(float gao) {

this.gao = gao;

System.out.println("底 = "+di+",高 = "+gao+ "的三角形的面积 = " + di*gao/2);

public static void main(String[] arg)

Trival trival = new Trival();

trival.setDi(3);

trival.setGao(5);

trival.findArea();

}

当编辑并运行一个Java程序时

需要同时涉及到这四种方面。使用文字编辑软件(例如记事本、写字板、UltraEdit等)或集成开发环境(Eclipse、MyEclipse等)在Java源文件中定义不同的类,通过调用类(这些类实现了Java API)中的方法来访问资源系统;

把源文件编译生成一种二进制中间码,存储在class文件中,然后再通过运行与操作系统平台环境相对应的Java虚拟机来运行class文件,执行编译产生的字节码,调用class文件中实现的方法来满足程序的Java API调用。

以上内容参考:百度百科-Java

java中设计实现地址概念的类Address,其具有属性:省,市,街道,门牌号,邮编,具有能设置和获取属性的方法.

你可以实现一个javaBean的java类,使用的时候直接调用就可以了

public class Address{

    private String province,city,post;

    private int street;

    public Address(){

    }

    public Address(String province,String city,String post,int street){

        this.province = province;

        this.city = city;

        this.post = post;

        this.street = street;

    }

    //下面提供调用的getter和setter方法

    public void setProvince(String province){

        this.province = province;

    }

    public String getProvince {

        return province;

    }

    public void setCity(String city) {

        this.city = city;

    }

    public String getCity {

        return city;

    }

    public void setPost(String post){

        this.post = post;

    }

    public String getPost(){

        return post;

    }

    public void setStreet(int street){

        this.street = street;

    }

    public int getStreet(){

        return street;

    }

}

这就完成了Address的javaBean类的定义,使用的时候直接调用set和get即可

java如何实现电子地图的定位

CellInfoManager

import java.lang.reflect.Method;

import java.util.Iterator;

import java.util.List;

import org.json.JSONArray;

import org.json.JSONException;

import org.json.JSONObject;

import android.content.Context;

import android.telephony.CellLocation;

import android.telephony.NeighboringCellInfo;

import android.telephony.PhoneStateListener;

import android.telephony.TelephonyManager;

import android.telephony.gsm.GsmCellLocation;

import android.util.Log;

public class CellInfoManager {

private int asu;

private int bid;

private int cid;

private boolean isCdma;

private boolean isGsm;

private int lac;

private int lat;

private final PhoneStateListener listener;

private int lng;

private int mcc;

private int mnc;

private int nid;

private int sid;

private TelephonyManager tel;

private boolean valid;

private Context context;

public CellInfoManager(Context paramContext) {

this.listener = new CellInfoListener(this);

tel = (TelephonyManager) paramContext.getSystemService(Context.TELEPHONY_SERVICE);

this.tel.listen(this.listener, PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_SIGNAL_STRENGTH);

context = paramContext;

}

public static int dBm(int i) {

int j;

if (i = 0 i = 31)

j = i * 2 + -113;

else

j = 0;

return j;

}

public int asu() {

return this.asu;

}

public int bid() {

if (!this.valid)

update();

return this.bid;

}

public JSONObject cdmaInfo() {

if (!isCdma()) {

return null;

}

JSONObject jsonObject = new JSONObject();

try {

jsonObject.put("bid", bid());

jsonObject.put("sid", sid());

jsonObject.put("nid", nid());

jsonObject.put("lat", lat());

jsonObject.put("lng", lng());

} catch (JSONException ex) {

jsonObject = null;

Log.e("CellInfoManager", ex.getMessage());

}

return jsonObject;

}

public JSONArray cellTowers() {

JSONArray jsonarray = new JSONArray();

int lat;

int mcc;

int mnc;

int aryCell[] = dumpCells();

lat = lac();

mcc = mcc();

mnc = mnc();

if (aryCell == null || aryCell.length 2) {

aryCell = new int[2];

aryCell[0] = cid;

aryCell[1] = -60;

}

for (int i = 0; i aryCell.length; i += 2) {

try {

int j2 = dBm(i + 1);

JSONObject jsonobject = new JSONObject();

jsonobject.put("cell_id", aryCell[i]);

jsonobject.put("location_area_code", lat);

jsonobject.put("mobile_country_code", mcc);

jsonobject.put("mobile_network_code", mnc);

jsonobject.put("signal_strength", j2);

jsonobject.put("age", 0);

jsonarray.put(jsonobject);

} catch (Exception ex) {

ex.printStackTrace();

Log.e("CellInfoManager", ex.getMessage());

}

}

if (isCdma())

jsonarray = new JSONArray();

return jsonarray;

}

public int cid() {

if (!this.valid)

update();

return this.cid;

}

public int[] dumpCells() {

int[] aryCells;

if (cid() == 0) {

aryCells = new int[0];

return aryCells;

}

ListNeighboringCellInfo lsCellInfo = this.tel.getNeighboringCellInfo();

if (lsCellInfo == null || lsCellInfo.size() == 0) {

aryCells = new int[1];

int i = cid();

aryCells[0] = i;

检举补充回答:

return aryCells;

}

int[] arrayOfInt1 = new int[lsCellInfo.size() * 2 + 2];

int j = 0 + 1;

int k = cid();

arrayOfInt1[0] = k;

int m = j + 1;

int n = asu();

arrayOfInt1[j] = n;

IteratorNeighboringCellInfo iter = lsCellInfo.iterator();

while (true) {

if (!iter.hasNext()) {

break;

}

NeighboringCellInfo localNeighboringCellInfo = (NeighboringCellInfo) iter.next();

int i2 = localNeighboringCellInfo.getCid();

if ((i2 = 0) || (i2 == 65535))

continue;

int i3 = m + 1;

arrayOfInt1[m] = i2;

m = i3 + 1;

int i4 = localNeighboringCellInfo.getRssi();

arrayOfInt1[i3] = i4;

}

int[] arrayOfInt2 = new int[m];

System.arraycopy(arrayOfInt1, 0, arrayOfInt2, 0, m);

aryCells = arrayOfInt2;

return aryCells;

}

public JSONObject gsmInfo() {

if (!isGsm()) {

return null;

}

JSONObject localObject = null;

while (true) {

try {

检举补充回答: JSONObject localJSONObject1 = new JSONObject();

String str1 = this.tel.getNetworkOperatorName();

localJSONObject1.put("operator", str1);

String str2 = this.tel.getNetworkOperator();

if ((str2.length() == 5) || (str2.length() == 6)) {

String str3 = str2.substring(0, 3);

String str4 = str2.substring(3, str2.length());

localJSONObject1.put("mcc", str3);

localJSONObject1.put("mnc", str4);

}

localJSONObject1.put("lac", lac());

int[] arrayOfInt = dumpCells();

JSONArray localJSONArray1 = new JSONArray();

int k = 0;

int m = arrayOfInt.length / 2;

while (true) {

if (k = m) {

localJSONObject1.put("cells", localJSONArray1);

localObject = localJSONObject1;

break;

}

int n = k * 2;

int i1 = arrayOfInt[n];

int i2 = k * 2 + 1;

int i3 = arrayOfInt[i2];

JSONObject localJSONObject7 = new JSONObject();

localJSONObject7.put("cid", i1);

localJSONObject7.put("asu", i3);

localJSONArray1.put(localJSONObject7);

k += 1;

}

} catch (JSONException localJSONException) {

localObject = null;

}

}

}

public boolean isCdma() {

if (!this.valid)

update();

用JAVA语言编程实现一个用户登录窗口

方法一:

采用JOptionPane中的一个非常有用的静态方法 showOptionPane();

源码如下:

import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JLabel;

import javax.swing.JTextField;

import javax.swing.JPasswordField;

import javax.swing.JOptionPane;

import javax.swing.BoxLayout;

import javax.swing.Box;

import javax.swing.BorderFactory;

public class Login1 {

public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

static void createAndShowGUI() {

JFrame mainFrame = new JFrame();

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainFrame.setBounds(250,250,400,300);

mainFrame.setVisible(false);

usernameField = new JTextField(10);

passwordField = new JPasswordField(10);

Object[] options = {"登录","取消"};

int i = JOptionPane.showOptionDialog(null,createLoginPanel(),"登录信息",JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE,null,options,options[0]);

if(i==0) {

String username = usernameField.getText();

String password = passwordField.getText();

if(!username.equals("") !password.equals("")) {

mainFrame.getContentPane().add(new JLabel("用户名:"+username+" 密码是:"+password,JLabel.CENTER));

mainFrame.show();

}

else {

JOptionPane.showMessageDialog(null,"用户名和密码不能为空","提示",JOptionPane.WARNING_MESSAGE);

System.exit(1);

}

}

else System.exit(0);

}

static JPanel createLoginPanel() {

JPanel ret = new JPanel();

JPanel usernamePanel = new JPanel();

usernamePanel.add(new JLabel("用户名:",JLabel.RIGHT));

usernamePanel.add(usernameField);

JPanel passwordPanel = new JPanel();

passwordPanel.add(new JLabel("密 码:",JLabel.RIGHT));

passwordPanel.add(passwordField);

Box box = new Box(BoxLayout.Y_AXIS);

box.add(usernamePanel); box.add(passwordPanel);

ret.add(box);

ret.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(244,144,44)),"填写登录信息"));

return ret;

}

static JFrame mainFrame = null;

static JTextField usernameField = null;

static JPasswordField passwordField = null;

}

运行:

javac -deprecation Login1.java

java Login

(因为有一个过期的API,所以用了 -deprecation 命令)

方法二,使用了两个JFrame类共同实现,第一次显示第一个frame,当点了登录后且操作合法时,第一个窗口就被释放了 dispose();再显示第二个窗口:

源码如下:

import java.awt.Color;

import java.awt.BorderLayout;

import java.awt.event.*;

import javax.swing.*;

public class Login2 {

public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

static void createAndShowGUI() {

//////////////////////////////////////////////////////////////

loginWindow = new JFrame("登录信息");

loginWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

loginWindow.setBounds(350,350,250,200);

loginWindow.setResizable(false);

JPanel usernamePanel = new JPanel();

usernamePanel.add(new JLabel("用户名:",JLabel.CENTER));

usernamePanel.add(usernameField);

JPanel passwordPanel = new JPanel();

passwordPanel.add(new JLabel("密 码:",JLabel.CENTER));

passwordPanel.add(passwordField);

Box box = new Box(BoxLayout.Y_AXIS);

box.add(usernamePanel); box.add(passwordPanel);

JPanel infoPanel = new JPanel();

infoPanel.add(box);

infoPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(244,144,44)),"填写登录信息"));

JButton submitButton = new JButton("登录");

JButton cancelButton = new JButton("取消");

submitButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

String username = usernameField.getText();

String password = passwordField.getText();

if(!username.equals("") !password.equals("")) {

loginWindow.dispose();

mainFrame.getContentPane().add(new JLabel("用户名:"+username+" 密码是:"+password,JLabel.CENTER));

mainFrame.setVisible(true);

}

else {

JOptionPane.showMessageDialog(null,"用户名和密码不能为空","提示",JOptionPane.WARNING_MESSAGE);

System.exit(1);

}

}

});

cancelButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

JPanel buttonPanel = new JPanel();

buttonPanel.add(submitButton); buttonPanel.add(cancelButton);

loginWindow.getContentPane().add(infoPanel,BorderLayout.CENTER);

loginWindow.getContentPane().add(buttonPanel,BorderLayout.SOUTH);

loginWindow.getContentPane().add(new JPanel(),BorderLayout.EAST);

loginWindow.getContentPane().add(new JPanel(),BorderLayout.WEST);

loginWindow.setVisible(true);

/////////////////////////////////////////////////////////////////

mainFrame = new JFrame();

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainFrame.setBounds(250,250,400,300);

mainFrame.setVisible(false);

}

static JFrame loginWindow,mainFrame;

static final JTextField usernameField = new JTextField(10);

static final JPasswordField passwordField = new JPasswordField(10);

}

运行:

javac -deprecation Login2.java

java Login2

java是实现什么功能

Java是Sun公司推出的一种编程语言。它是一种通过解释方式来执行的语言,语法规则和C++类似。同时,Java也是一种跨平台的程序设计语言。用Java语言编写的程序叫做“Applet”(小应用程序),用编译器将它编译成类文件后,将它存在WWW页面中,并在HTML档上作好相应标记,用户端只要装上Java的客户软件就可以在网上直接运行“Applet”。 Java非常适合于企业网络和Internet环境,现在已成为Internet中最受欢迎、最有影响的编程语言之一。 Java有许多值得称道的优点,如简单、面向对象、分布式、解释性、可靠、安全、结构中立性、可移植性、高性能、多线程、动态性等。Java摈弃了C++中各种弊大于利的功能和许多很少用到的功能。 Jave可以运行与任何微处理器,用Java开发的程序可以在网络上传输,并运行于任何客户机上。

java 实现截屏!

主要是利用java的几个先有的函数,如Robot这个类的一个方法createScreenCapture一个获得一个任意大小的屏幕图像(在这里是全屏图像),而所谓的截图就是在这个图像上画出一个矩形,再利用上面的方法获得这部分的图像,程序中的cf.setAlwaysOnTop(true)是必需的;看起来是在屏幕上截图,其实只是在一个在一个内镶有桌面背景的JFrame中截图。不知道还有没有其他的好方法~

附上代码:

import java.awt.*;

import java.awt.image.*;

import java.awt.event.*;

import java.io.File;

import javax.imageio.ImageIO;

import javax.swing.*;

public class Camera {

/**

* @param args

*/

public static void main(String[] args) {

CameraJFrame cf=new CameraJFrame();

cf.setAlwaysOnTop(true);

cf.setUndecorated(true);

cf.setVisible(true);

}

}

class CameraJFrame extends JFrame

{

/**

*

*/

private static final long serialVersionUID = 1L;

Dimension di=Toolkit.getDefaultToolkit().getScreenSize();

public CameraJFrame()

{

setSize(di);

getContentPane().add(new CameraJPanel());

}

class CameraJPanel extends JPanel implements MouseListener,MouseMotionListener

{

/**

* flag主要是用来判别状态。

* 文件的格式名是unname+数字编号,格式是png

*/

private static final long serialVersionUID = 1L;

BufferedImage bi,get;

int startx,starty,endx,endy;

int flag=1;

String filename="unname";

String fileformat="png";

int count=1;

public CameraJPanel()

{

try

{

Robot ro=new Robot();

bi=ro.createScreenCapture(new Rectangle(0,0,di.width,di.height));

}

catch(Exception e)

{

e.printStackTrace();

}

addMouseListener(this);

addMouseMotionListener(this);

}

public void paintComponent(Graphics g)

{

g.drawImage(bi,0,0,di.width,di.height,this);

g.setColor(Color.red);

g.drawRect(startx, starty, endx-startx, endy-starty);

}

public void mouseClicked(MouseEvent e) {

// TODO Auto-generated method stub

if(e.getButton()==MouseEvent.BUTTON3)

{

System.exit(0);

}

else if(e.getClickCount()==2)

{

try

{

Robot ro=new Robot();

get=ro.createScreenCapture(new Rectangle(startx,starty,endx-startx,endy-starty));

String name=filename+String.valueOf(count++)+"."+fileformat;

File f=new File(name);

ImageIO.write(get, fileformat, f);

}

catch(Exception ex)

{

ex.printStackTrace();

}

flag=1; //置flag为1,以便重新开始截图。

startx=starty=endx=endy=0;

repaint();

}

}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mousePressed(MouseEvent e) {

if(flag==1)

{

startx=e.getX();

starty=e.getY();

}

}

public void mouseReleased(MouseEvent e) {

flag=0;

}

public void mouseDragged(MouseEvent e) {

flag=1;

endx=e.getX();

endy=e.getY();

repaint();

}

public void mouseMoved(MouseEvent e) {}

}

}

java实现di的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java实现dir和cd、java实现di的信息别忘了在本站进行查找喔。