「java实现定位功能」java线上问题定位
今天给各位分享java实现定位功能的知识,其中也会对java线上问题定位进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、java gui中怎么用jpanel实现组件的绝对定位
- 2、java如何实现多点定位?
- 3、java swing 如何实现查找定位功能
- 4、java中如何自动定位
- 5、java如何实现电子地图的定位
java gui中怎么用jpanel实现组件的绝对定位
相对定位是利用布局管理器GridBagLayout() 来实现的GridBagLayout 布局是根据GridBagConstraints() 来设定的GridBagConstraints主要有8个重要参数需要掌握非别是
gridx,gridy —— 设置组件的位置,
gridx设置为GridBagConstraints.RELATIVE代表此组件位于之前所加入组件的右边。
gridy设置为GridBagConstraints.RELATIVE代表此组件位于以前所加入组件的下面。
建议定义出gridx,gridy的位置以便以后维护程序。gridx=0,gridy=0时放在0行0列。
gridwidth,gridheight —— 用来设置组件所占的单位长度与高度,默认值皆为1。
你可以使用GridBagConstraints.REMAINDER常量,代表此组件为此行或此列的最后一个组件,而且会占据所有剩余的空间。
weightx,weighty —— 用来设置窗口变大时,各组件跟着变大的比例。
当数字越大,表示组件能得到更多的空间,默认值皆为0。
anchor —— 当组件空间大于组件本身时,要将组件置于何处。
有CENTER(默认值)、NORTH、NORTHEAST、EAST、SOUTHEAST、WEST、NORTHWEST选择。
insets —— 设置组件之间彼此的间距。
它有四个参数,分别是上,左,下,右,默认为(0,0,0,0)。
ipadx,ipady —— 设置组件间距,默认值为0。
GridBagLayout里的各种设置都必须通过GridBagConstraints,因此当我们将GridBagConstraints的参数都设置
好了之后,必须new一个GridBagConstraints的对象出来,以便GridBagLayout使用。
构造函数:
GirdBagLayout()建立一个新的GridBagLayout管理器。
GridBagConstraints()建立一个新的GridBagConstraints对象。
GridBagConstraints(int gridx,int gridy,
int gridwidth,int gridheight,
double weightx,double weighty,
int anchor,int fill, Insets insets,
int ipadx,int ipady)建立一个新的GridBagConstraints对象,并指定其参数的值
下面是我的例程:
实现
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Example extends JFrame{
private void makeComponent(GridBagLayout gbLaout,GridBagConstraints constraints,Component component)
{
gbLaout.setConstraints(component, constraints);
add(component);
}
public static void main(String args[]) {
Example exp=new Example();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
exp.setLayout(gridbag);
JButton jb1=new JButton("JButton1");
c.gridx=0;
c.gridy=0;
c.gridwidth=1;
c.gridheight=1;
c.weightx=1;
c.weighty=0;
c.anchor=GridBagConstraints.CENTER;
c.fill=GridBagConstraints.HORIZONTAL;
c.insets=new Insets(0,0,0,0);
c.ipadx=0;
c.ipady=0;
exp.makeComponent(gridbag,c,jb1);
JButton jb2=new JButton("JButton2");
c.gridx=1;
exp.makeComponent(gridbag,c,jb2);
JButton jb3=new JButton("JButton2");
c.gridx=2;
exp.makeComponent(gridbag,c,jb3);
JButton jb4=new JButton("JButton2");
c.gridx=3;
exp.makeComponent(gridbag,c,jb4);
JButton jb5=new JButton("JButton5");
c.gridx=0;
c.gridy=1;
c.gridheight=1;
c.gridwidth=4;
exp.makeComponent(gridbag,c,jb5);
JButton jb6=new JButton("JButton6");
c.gridx=0;
c.gridy=2;
c.gridwidth=3;
exp.makeComponent(gridbag,c,jb6);
JButton jb7=new JButton("JButton7");
c.gridx=3;
c.gridy=2;
c.gridwidth=1;
exp.makeComponent(gridbag,c,jb7);
JButton jb8=new JButton("JButton8");
c.gridx=0;
c.gridy=3;
c.gridwidth=1;
c.gridheight=2;
c.fill=GridBagConstraints.BOTH;
exp.makeComponent(gridbag,c,jb8);
JButton jb9=new JButton("JButton9");
c.gridx=1;
c.gridy=3;
c.gridwidth=3;
c.gridheight=1;
c.fill=GridBagConstraints.HORIZONTAL;
exp.makeComponent(gridbag,c,jb9);
JButton jb10=new JButton("JButton10");
c.gridx=1;
c.gridy=4;
c.gridwidth=3;
c.gridheight=1;
c.fill=GridBagConstraints.HORIZONTAL;
exp.makeComponent(gridbag,c,jb10);
exp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
exp.setSize(500,500);
exp.setVisible(true);
}
}
java如何实现多点定位?
这个就是计算吧,知道经纬度就相当于知道横纵坐标x,y,知道信号强度就相当于知道距离这个点的距离r,设你在的位置坐标是x0,y0。一个已知点的坐标是x1,y1。另一个一直点的坐标是x2,y2。所以(x1-x0)^2+(y1-y0)^2=r^2;(x2-x0)^2+(y2-y0)^2=r^2; 解方程就不用我教了。
java swing 如何实现查找定位功能
swing中使用text控件,控件内容中使用lucene等搜索技术。这个比较复杂,但是功能强大。否则就用效率低下的,将text的字符串获取,看是否包含单词(用string的方法),然后修改处一个新的字符串(添加颜色)赋给text
java中如何自动定位
自动定位需要特定的api,比如百度等。
在需要的地方调用第三方提供的api调用定位相关代码就好。
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实现定位功能的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java线上问题定位、java实现定位功能的信息别忘了在本站进行查找喔。