本文目錄一覽:
- 1、java怎麼讓圖形界面中的組件居中
- 2、java 圖形用戶界面組件顯示問題
- 3、java圖形界面GUI,什麼組件可以實現以下功能,求解
- 4、java圖形界面有兩類組件,分別是什麼?比較他們的優缺點。急求,在線等,高分
- 5、組件和容器的區別是什麼?列舉在Java圖形界面設計中有哪幾種容器?有哪些常用組件?
- 6、怎樣用java編寫圖形界面的Application程序
java怎麼讓圖形界面中的組件居中
用窗體的大小減去組件的大小除以2即可活的居中的位置
代碼示例,我寫的:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test extends JFrame
{
private JButton button;
public Test()
{
super(“按鈕居中顯示示例”);
button=new JButton(“滿意答案”);
button.setSize(100,50);
Container rongqi=this.getContentPane();
rongqi.setLayout(null);
rongqi.add(button);
setSize(400,200);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//關鍵代碼,設置按鈕位置
button.setBounds((this.getWidth()-button.getWidth()-5)/2,(this.getHeight()-28-button.getHeight())/2,
button.getWidth(),button.getHeight());
setVisible(true);
}
public static void main(String[]args)
{
new Test();
}
}
java 圖形用戶界面組件顯示問題
public void TestTextField() 並不是構造函數,構造函數是沒有返回值的
java圖形界面GUI,什麼組件可以實現以下功能,求解
swing 可以通過3個組件配合,模擬一個數字輸入組件
JavaFX 可以直接使用 Spinner組件實現, 效果如下
當然了也可以在JavaFX里使用動畫,來產生更有動感的效果;如下圖,使用了位置改變動畫,來產生動感;
拓展: 可以在swing里 使用JFXPanel 來使用JavaFX的組件~
java圖形界面有兩類組件,分別是什麼?比較他們的優缺點。急求,在線等,高分
一個是awt,另一個是javax.swing ;
1:java.awt是重量級的界面:它的組件分別有Button,Frame,Label,…..,還有事件介面,布局管理,優點:可以輕鬆的實現事件監聽和布局管理 缺點:組件的添加不足Javax.swing 那麼豐富,一般推薦使用javax.swing
2:javax.swing:輕量級的界面,它的組件包含了大部分的java.awt的組件,只不過沒有布局管理,優點:利於界面的管理和開發 缺點:布局管理和事件監聽都要在java.awt里裡面通過自身的實現才能夠使用
組件和容器的區別是什麼?列舉在Java圖形界面設計中有哪幾種容器?有哪些常用組件?
1.容器可以添加其他組件形成複合組件,比如在panel里可以添加button。容器本身也是一種組件
2.panel是最原始的容器,還有JPanel,JScrollPane,JSplitPane,JTabbedPane 等
3.常用的組件有JButton,JComboBox,JList,JMenu,Jtable等
怎樣用java編寫圖形界面的Application程序
java編寫圖形界面需要用到swing等組件,可以在eclipse中安裝windowbuilder來開發窗體,自動生成窗體代碼,然後自己再根據需要修改,如:
package mainFrame;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
public class Mian_login extends JFrame {
private JPanel contentPane;
private JTextField text_LoginName;
private JPasswordField Login_password;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
Mian_login frame = new Mian_login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Mian_login() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(500, 200, 443, 300);
setResizable(false);
setTitle(“登 錄”);
/*獲取系統按鈕樣式*/
String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(lookAndFeel);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setBounds(0, 0, 434, 272);
contentPane.add(panel);
panel.setLayout(null);
JButton btn_Login = new JButton(“\u767B\u5F55”);
btn_Login.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
}
});
btn_Login.setBounds(88, 195, 70, 23);
panel.add(btn_Login);
JButton btn_cancel = new JButton(“\u53D6\u6D88”);
btn_cancel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
dispose();
}
});
btn_cancel.setBounds(268, 195, 70, 23);
panel.add(btn_cancel);
JLabel lblNewLabel_name = new JLabel(“\u7528\u6237\u540D”);
lblNewLabel_name.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_name.setOpaque(true);
lblNewLabel_name.setBounds(88, 48, 70, 23);
panel.add(lblNewLabel_name);
JLabel lblNewLabel_passwd = new JLabel(“\u5BC6\u7801”);
lblNewLabel_passwd.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_passwd.setOpaque(true);
lblNewLabel_passwd.setBounds(88, 102, 70, 23);
panel.add(lblNewLabel_passwd);
JCheckBox chckbx_remember = new JCheckBox(“\u8BB0\u4F4F\u5BC6\u7801”);
chckbx_remember.setBounds(102, 150, 84, 23);
panel.add(chckbx_remember);
text_LoginName = new JTextField();
text_LoginName.setBounds(182, 48, 156, 23);
panel.add(text_LoginName);
text_LoginName.setColumns(10);
Login_password = new JPasswordField();
Login_password.setBounds(182, 102, 156, 23);
panel.add(Login_password);
JCheckBox chckbx_AutoLogin = new JCheckBox(“\u81EA\u52A8\u767B\u5F55”);
chckbx_AutoLogin.setBounds(233, 150, 84, 23);
panel.add(chckbx_AutoLogin);
JLabel Label_background = new JLabel(“”);
Label_background.setIcon(new ImageIcon(“E:\\JAVA_workplace\\0002-\u754C\u9762\u8BBE\u8BA1\\images\\background3.jpg”));
Label_background.setBounds(0, 0, 437, 272);
contentPane.add(Label_background);
}
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/219633.html