導航:首頁 > 編程語言 > javajdesktop

javajdesktop

發布時間:2023-05-12 03:20:52

1. java中的desktopPane類起什麼作用

Desktop Pane是一種特殊的Layered pane,用來建立虛擬桌面(Vitual
Desktop).它可以顯示並管理眾多Internal Frame之間的層次關系。以下是JDesktopPane的類層次結構圖;
類層次結構圖:
java.lang.Object
--java.awt.Component
--java.awt.Container
--javax.swing.JComponent
--javax.swing.JLayeredPane
--javax.swing.JDesktop

強烈建議看看這里:

http://blog.csdn.net/heimaoxiaozi/archive/2007/01/31/1499256.aspx

2. 題目如圖

按照你的要求利用JAVA AWT組件編寫的Java程序如下:

import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class AFD extends Frame implements ActionListener{
Choice c=new Choice();
TextField tf1=new TextField(5);
TextField tf2=new TextField(5);
TextField tf3=new TextField(5);
Button b=new Button("=");
Panel p=new Panel();
AFD(){
super("四則運算");
c.add("+");c.add("-");c.add("*");c.add("/");
孫瞎p.setBackground(Color.CYAN);
b.setBackground(Color.CYAN);
tf3.setEditable(false);
p.add(tf1);p.add(c);p.add(tf2);p.add(b);p.add(tf3);
b.addActionListener(this);
add(p);
setSize(300, 100);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}});
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==b){
double d1=Double.parseDouble(tf1.getText().trim());
double d2=Double.parseDouble(tf2.getText().trim());
String s=c.getSelectedItem();
if(s.equals("+")){
汪仔tf3.setText(String.valueOf(d1+d2));
}else if(s.equals("-")){
tf3.setText(String.valueOf(d1-d2));
}else if(s.equals("*")){
tf3.setText(String.valueOf(d1*d2));
}else if(s.equals("/")){
tf3.setText(String.valueOf(d1/d2));
}
}
}
public static void main(String[] args) {
困凱汪new AFD();
}
}

運行結果:

3. java桌面資料庫應用程序生成jar文件後,在本機運行正常,但在其他機器上異常

1 檢查SQL SERVER 是否允許遠程訪問.具體步驟:

1)打開"企業管理器",打開控制台根目錄>SQL Server 組>資料庫
2)在相應灶轎"資料庫"上單擊右鍵,選擇"屬性"
3)選擇"連接"選項卡,檢查"遠程伺服器連接"下,RPC服務是否選擇.

2 使用telnet IP地址 1433,系統是否提示連接出錯,如系統提示出錯
檢查是否防火牆屏蔽了SQL SERVER 或 java IDE 的網路訪問埠
如果是,關閉防火牆,重新啟動SQL SERVER和java IDE,進行測試,
如果系統仍提李辯液示上述錯誤,嘗試下列步驟

3 檢查SQL SERVER 埠號及是否啟用了TCP/IP協議,具體步驟:

1)打開"企業管理器",打開控制台根目錄>SQL Server 組>資料庫
2)在相應"資料庫"上單擊右鍵,選擇"屬性"
3)選擇"常規"選項卡,點擊"網路配置",如啟用的協議中無"哪物TCP/IP協議"將其加入
4)選擇"TCP/IP協議",點擊"屬性",檢查其埠號是否為1433
5)如埠號為1433將其修改為其它埠號,修改jdbc連接語句,將埠號同樣改為新啟用的埠號,如jdbc:microsoft:sqlserver://server_name:1400(假設新埠號為 1400)

4. java 窗口背景圖片無法載入

你好,你這種情況我曾經遇過。

不能顯示背景圖片的原因是它宏談被其他組件擋住了,主要原因是布局的問題,你設置為空,JFrame就不會幫你布局,你要特別注意添加組件的順序,我特意為你寫了一個符合你要求的JFrame,跟你那個完全一樣,只要你的圖片跟我的圖片一樣就行了。

解決辦法(參照如下代碼):

/*

*Tochangethistemplate,chooseTools|Templates

*andopenthetemplateintheeditor.

*/

/*

*MyIndex.java

*

*Createdon2011-5-8,1:00:26

*/

packagetestjframebgcolor;

/**

*

*@authorStudy

*/

.swing.JFrame{

/**CreatesnewformMyIndex*/

publicMyIndex(){

initComponents();

}

/**

*initializetheform.

沖臘*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis

*.

*/

@SuppressWarnings("unchecked")

//<editor-folddefaultstate="collapsed"desc="GeneratedCode">

privatevoidinitComponents(){

lb1=newjavax.swing.JLabel();

Enter=newjavax.swing.JButton();

Login=newjavax.swing.JButton();

tf2=newjavax.swing.JTextField();

tf1=newjavax.swing.JTextField();

lb2=newjavax.swing.JLabel();

imgLabel=newjavax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setName("Form");//NOI18N

getContentPane().setLayout(null);

org.jdesktop.application.ResourceMapresourceMap=org.jdesktop.application.Application.getInstance(testjframebgcolor.TestJFrameBGColorApp.class).getContext().getResourceMap(MyIndex.class);

lb1.setText(resourceMap.getString("lb1.text"));//NOI18N

lb1.setName("lb1");//NOI18N

蔽判碰getContentPane().add(lb1);

lb1.setBounds(75,85,60,20);

Enter.setText(resourceMap.getString("Enter.text"));//NOI18N

Enter.setName("Enter");//NOI18N

getContentPane().add(Enter);

Enter.setBounds(230,185,65,20);

Login.setText(resourceMap.getString("Login.text"));//NOI18N

Login.setName("Login");//NOI18N

getContentPane().add(Login);

Login.setBounds(100,185,65,20);

tf2.setName("tf2");//NOI18N

getContentPane().add(tf2);

tf2.setBounds(165,125,120,20);

tf1.setText(resourceMap.getString("tf1.text"));//NOI18N

tf1.setName("tf1");//NOI18N

getContentPane().add(tf1);

tf1.setBounds(165,85,120,20);

lb2.setText(resourceMap.getString("lb2.text"));//NOI18N

lb2.setName("lb2");//NOI18N

getContentPane().add(lb2);

lb2.setBounds(75,125,60,20);

imgLabel.setIcon(resourceMap.getIcon("imgLabel.icon"));//NOI18N

imgLabel.setText(resourceMap.getString("imgLabel.text"));//NOI18N

imgLabel.setName("imgLabel");//NOI18N

imgLabel.setOpaque(true);

getContentPane().add(imgLabel);

imgLabel.setBounds(0,0,400,330);

setBounds(450,250,400,330);

}//</editor-fold>

/**

*@

*/

publicstaticvoidmain(Stringargs[]){

java.awt.EventQueue.invokeLater(newRunnable(){

publicvoidrun(){

newMyIndex().setVisible(true);

}

});

}

//Variablesdeclaration-donotmodify

protectedjavax.swing.JButtonEnter;

protectedjavax.swing.JButtonLogin;

protectedjavax.swing.JLabelimgLabel;

protectedjavax.swing.JLabellb1;

protectedjavax.swing.JLabellb2;

protectedjavax.swing.JTextFieldtf1;

protectedjavax.swing.JTextFieldtf2;

//Endofvariablesdeclaration

}

5. java JDIC 無法使用

有兩個DLL文件要放在環境變數PATH裡面。或者放到當前運費的目錄中。
可以放在SYSTEM32或者JRE bin目錄里。

6. java編程問題:在swing面板中展示某一URL地址的頁面

你可以寫個簡單的JAVA瀏覽器
這有個源碼

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.jdesktop.jdic.browser.IWebBrowser;
import org.jdesktop.jdic.browser.WebBrowser;
import org.jdesktop.jdic.browser.WebBrowserEvent;
import org.jdesktop.jdic.browser.WebBrowserListenerAdapter;

/**
*
* @author hadeslee
*/
public class Test1 extends JPanel implements ActionListener {

private JTextField input;
private JButton go;
private IWebBrowser web;

public Test1() {
super(new BorderLayout());
initWindow();
}

private void initWindow() {
try {
web = new WebBrowser();
web.addWebBrowserListener(new MyListener());
go = new JButton("轉到");
input = new JTextField();
JPanel up = new JPanel(new BorderLayout());
up.add(input, BorderLayout.CENTER);
up.add(go, BorderLayout.EAST);
this.add(up, BorderLayout.NORTH);
this.add(web.asComponent(), BorderLayout.CENTER);
input.addActionListener(this);
go.addActionListener(this);
} catch (Exception ex) {
Logger.getLogger(Test1.class.getName()).log(Level.SEVERE, null, ex);
}
JFrame jf = new JFrame("JAVA瀏覽器");
jf.add(this, BorderLayout.CENTER);
jf.setSize(500, 300);
jf.setLocationRelativeTo(null);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent ae) {
doOpen();
}

private void doOpen() {
try {
String text = input.getText();
if (text == null || text.equals("")) {
return;
}
if (!text.toLowerCase().startsWith("http://")) {
text = "http://" + text;
}
web.setURL(new URL(text));
} catch (MalformedURLException ex) {
Logger.getLogger(Test1.class.getName()).log(Level.SEVERE, null, ex);
}
}

public static void main(String[] args) {
new Test1();
}

private class MyListener extends WebBrowserListenerAdapter {

private MyListener() {}

@Override
public void documentCompleted(WebBrowserEvent arg0) {
System.out.println("文檔下載完。。。");
web.executeScript("alert('文檔下載完畢!')");
// web.setContent("<html><H1>Hello world!!<H1>" +
// "<a href=http://www.google.cn>點我</a></html>");
// web.removeWebBrowserListener(this);
}
}
}

7. Java的「靜態庫鏈接」

Java的庫組織方式就是 動態鏈接 的 從一個Java的jar包運行有可能要接一堆classpath就知道 和基於靜態鏈接的C語言要實現動態鏈接要做額外的事情相似 Java要想實現類似C的靜態鏈接也要做很多額外的事

用類似Fat Jar的方法 把所有的依賴庫打包的最後的庫中 其實不是靜態鏈接——C的靜態鏈接只把需要的代碼復制過來 不是眉毛鬍子一把抓 按說 以Java的思想 靜態鏈接不是很必要 因此也就沒有原生支持 但實踐和理論畢竟差距很遠 不是每個庫都是標准庫 假設你從別人的庫中引用了幾個類 為了支持你的程序 你必須提供別人的庫(假設這個庫並不流塌廳行) 再假設你自己寫了一個庫稿衫耐 以後再開發類似的程序就從庫中派生 當然你不想把所有的代碼都發行出去 這個問題在Netbeans上更為明顯 Netbeans提供了一個swing框架 用起來當然很方便 但是當發行程序的時候你就會發現 Netbeans很負責任的把依賴庫放到發行目錄的lib下 居然有將近 M (禁掉粗口) 光寫一個窗口就要 M!

ProGuard不光是個混淆器 它也能解決靜態鏈接的問題 用它自己的話說是 It detects and removes unused classes fields methods and attributes 下面給出的是在Netbeans中用的Ant腳本 修改項目的build xml 添加

<target name= post jar > <taskdef resource= proguard/ant/task properties classpath= ${libs proguard classpath} /> <file src= ${dist jar} dest= ${dist dir}/pre jar /> <proguard warn= false obfuscate= false > <libraryjar path= ${java home}/lib/rt jar />鍵春 <injar path= ${javac classpath} filter= !META INF/MANIFEST MF /> <injar path= ${dist dir}/pre jar /> <outjar path= ${dist jar} /> <keep name= ${main class} > <method name= main /> </keep> <keep name= jdesktop bean *** inding ext BeanAdapterProvider /> <keepclasseswithmembernames> <method name= getServiceNames /> </keepclasseswithmembernames> <keepclasseswithmembernames> <method name= addPropertyChangeListener /> </keepclasseswithmembernames> </proguard> </target>

lishixin/Article/program/Java/hx/201311/26546

8. java 中string里replaceall中使用正則出錯的疑問!

另一位給出的是錯誤的。

java對於正則一塊,只要是含/n的正則表達式,處理時,匹配出的字元蔽毀串長時,就會出錯。

可以,先只區配/n,比如替換成其它字串。"|||"
然後,再用replaceall,進行處理,把需要刪除的刪除掉。
最後,再用替換戚搭,將"|||"替換回"\n" ,即可。高並拿

9. java窗口背景顏色怎麼設定用setBackground()好像不行,請大俠指教!

你好!

首先,你說的Java窗口是指JFrame或者Frame

其次,你說的窗口背景顏色是指直接調用JFrame或者Frame的setBackground(Colorcolor)方法設置後顯示出來的顏色。其實,你的想法是正確的,但是我想提醒你的是,你沒搞明白JFrame的顯示機制。在你直接調用這個方法後,你的確設置了背景顏色,而你看到的卻不是直接的JFrame或者Frame,而是JFrame.getContentPane().而JFrame上的contentPane默認是Color.WHITE的,所以,無論你對JFrame或者Frame怎麼設置背景顏色,你看到的都只是contentPane.

最後,講解決辦法:

辦法A:在完成初始化,調用getContentPane()方法得到一個contentPane容器,然後將其設置為不可見,即setVisible(false)。這樣,你就可以看到JFrame的廬山真面貌啦!

核心代碼this.getContentPane().setVisible(false);//得到contentPane容器,設置為不可見

實例完整代碼如下:

/*

*TestJFrameBGColor.java

*

*Createdon2011-5-8,0:21:20

*/

packagetestjframebgcolor;

importjava.awt.Color;

/**

*

*@author葉科良

*/

.swing.JFrame{

/***/

publicTestJFrameBGColor(){

initComponents();

this.getContentPane().setVisible(false);//得到contentPane容器,設置為不可見

}

/**

*initializetheform.

*WARNING:DoNOTmodifythiscode.Thecontentofthismethodis

*.

*/

@SuppressWarnings("unchecked")

//<editor-folddefaultstate="collapsed"desc="GeneratedCode">

privatevoidinitComponents(){

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

org.jdesktop.application.ResourceMapresourceMap=org.jdesktop.application.Application.getInstance(testjframebgcolor.TestJFrameBGColorApp.class).getContext().getResourceMap(TestJFrameBGColor.class);

setBackground(resourceMap.getColor("Form.background"));//NOI18N

setName("Form");//NOI18N

javax.swing.GroupLayoutlayout=newjavax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0,400,Short.MAX_VALUE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0,300,Short.MAX_VALUE)

);

pack();

}//</editor-fold>

/**

*@

*/

publicstaticvoidmain(Stringargs[]){

java.awt.EventQueue.invokeLater(newRunnable(){

publicvoidrun(){

newTestJFrameBGColor().setVisible(true);

}

});

}

//Variablesdeclaration-donotmodify

//Endofvariablesdeclaration

}

方法B:將contentPane的顏色設置為你想要的顏色,而不是對JFrame本身設置,

核心代碼:this.getContentPane().setBackground(Color.red);//設置contentPane為紅色

將核心代碼替換方法A核心代碼即可實現

方法C:為JFrame添加一個Panel或者JLabel等其他組件,設置其顏色為你想要的顏色,然後將其覆蓋JFrame窗口即可

閱讀全文

與javajdesktop相關的資料

熱點內容
更新後版本英文怎麼說 瀏覽:267
桌面雲配置文件分離 瀏覽:505
iphone5如何升級4g網路 瀏覽:5
團購是在哪個app 瀏覽:897
打開多個word文檔圖片就不能顯示 瀏覽:855
騰訊新聞怎麼切換版本 瀏覽:269
app安裝失敗用不了 瀏覽:326
桌面文件滑鼠點開會變大變小 瀏覽:536
手機誤刪系統文件開不了機 瀏覽:883
微信兔子甩耳朵 瀏覽:998
android藍牙傳文件在哪裡 瀏覽:354
蘋果6s軟解是真的嗎 瀏覽:310
c語言代碼量大 瀏覽:874
最新網路衛星導航如何使用 瀏覽:425
以下哪些文件屬於圖像文件 瀏覽:774
zycommentjs 瀏覽:414
確認全血細胞減少看哪些數據 瀏覽:265
文件有哪些要求 瀏覽:484
cad打開時會出現兩個文件 瀏覽:65
什麼是轉基因網站 瀏覽:48

友情鏈接