當前位置:首頁 » 編程語言 » java窗體

java窗體

發布時間: 2022-01-08 17:07:11

java 窗體事件

import java.awt.event.*;

import javax.swing.*;

public class WindowEvent extends JFrame{
public static void main(){
WindowEvent frame = new WindowEvent();
frame.setVisible(true);
}
public WindowEvent(){
super();
addWindowFocusListener( new MYWindowFocusListener());
setTitle("WindowEvent");
setBounds(100,100,500,375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MYWindowFocusListener implements WindowFocusListener{

public void windowGainedFocus(java.awt.event.WindowEvent e) {

}
public void windowLostFocus(java.awt.event.WindowEvent e) {

}
}

}

private class MYWindowFocusListener() implements WindowFocusListener{

MYWindowFocusListener是個內部類 後面不能加()它是類不是方法,應該是
private class MYWindowFocusListener implements WindowFocusListener{

Ⅱ java圖形界面子窗體怎麼弄

實在太長了!我都貼了好幾次都沒貼完,把核心方法給你貼出來: /**
* 保證只打開一個內部視窗的方法
* @param frame 要呼叫的內部視窗對象引用
*/
private void openOnlyOneInternalFrame(JInternalFrame frame) {
// 獲取桌面面板組件數組
JInternalFrame[] frames = pnlDsk.getAllFrames();
boolean isExist = false;
// 遍歷查找指定引用的內部視窗組件是否存在
for (JInternalFrame tmpFrame : frames) {
if (tmpFrame == frame) {
isExist = true;
}
}
// 如果不存在則添加到桌面面板
if (!isExist) {
pnlDsk.add(frame);
// 設置內部視窗位置居中
int x = (pnlDsk.getWidth() - frame.getWidth()) / 2;
int y = (pnlDsk.getHeight() - frame.getHeight()) / 2;
frame.setLocation(x, y);
}
// 將被呼叫內部視窗重新以默認方式布局(解決最小化後還原默認大小的問題)
frame.pack();
// 將被呼叫內部視窗顯示
frame.setVisible(true);
// 將被呼叫內部視窗置頂
// 方式一: 從類 java.awt.Window 繼承的方法
// frame.toFront();
// 方式二:從類 javax.swing.JInternalFrame 繼承的方法
frame.moveToFront();

// 將被呼叫內部視窗設置為選中狀態(標題欄高亮)
try {
frame.setSelected(true);
} catch (PropertyVetoException ex) {
ex.printStackTrace();
}
} ------------------------------------- 要源代碼就加我QQ,或發我QQ郵件,我回給你。

Ⅲ 求助:java窗體

/*
* StoreFrame.java
*
* Created on __DATE__, __TIME__
*/

/**
*
* @author __USER__
*/
public class StoreFrame extends javax.swing.JFrame {

/** Creates new form StoreFrame */
public StoreFrame() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem5 = new javax.swing.JMenuItem();
jMenuItem6 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jMenuBar1.setBackground(new java.awt.Color(0, 128, 255));

jMenu1.setText("\u7cfb\u7edf");
jMenuBar1.add(jMenu1);

jMenu2.setText("\u529f\u80fd");

jMenuItem1.setBackground(new java.awt.Color(0, 51, 255));
jMenuItem1.setText("\u5546\u54c1\u5165\u5e93");
jMenu2.add(jMenuItem1);

jMenuItem3.setText("\u5546\u54c1\u51fa\u5e93");
jMenu2.add(jMenuItem3);

jMenuItem2.setText("\u5546\u54c1\u67e5\u8be2");
jMenu2.add(jMenuItem2);

jMenuItem4.setText("\u5546\u54c1\u7edf\u8ba1");
jMenu2.add(jMenuItem4);

jMenuItem5.setText("\u5546\u54c1\u76d8\u70b9");
jMenu2.add(jMenuItem5);

jMenuItem6.setText("\u7cfb\u7edf\u7ba1\u7406");
jMenu2.add(jMenuItem6);

jMenuBar1.add(jMenu2);

jMenu3.setText("\u5e2e\u52a9");
jMenuBar1.add(jMenu3);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.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, 276,
Short.MAX_VALUE));

pack();
}// </editor-fold>
//GEN-END:initComponents

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new StoreFrame().setVisible(true);
}
});
}

//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
private javax.swing.JMenuItem jMenuItem6;
// End of variables declaration//GEN-END:variables

}

Ⅳ java窗體應用程序設計

程序如下:
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ChaneBG extends JFrame implements ActionListener
{
private JButton black;
private JButton white;
private JPanel panel;
public ChaneBG()
{
black = new JButton("黑色");
white = new JButton("白色");

panel = new JPanel();
panel.setBackground(Color.YELLOW);

panel.add(black);
panel.add(white);
add(panel);

setTitle("窗體顏色");
setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - 300)/2,
(Toolkit.getDefaultToolkit().getScreenSize().height - 200)/2, 300, 200);
setVisible(true);

this.black.addActionListener(this);
this.white.addActionListener(this);
}

public static void main(String[] args)
{
new ChaneBG();
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == this.black)
{
this.panel.setBackground(Color.BLACK);
repaint();
}

if(e.getSource() == this.white)
{
this.panel.setBackground(Color.WHITE);
repaint();
}
}
}

有問題歡迎提問,滿意請採納,謝謝!

Ⅳ java窗體滿分項目

給你個建議,不要學習java中的swing,java在這方面,自己都不玩了。
去學習:spring->spring boot->spring cloud吧
如果你針對窗體項目感興趣,去學習.NET的wpf

Ⅵ 這個java窗體怎麼寫出來

Java程序:

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;


public class Test extends JFrame implements ActionListener {

protected JList lstLeft = null;

protected JList lstRight = null;

protected JButton btnAdd = null;

protected String[] arr = {"新聞", "娛樂", "體育", "教育"};


public Test() {

super("列表框");


initComponent();


this.setSize(400, 300);

this.setVisible(true);

this.setLayout(new FlowLayout());

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}


public void initComponent() {

lstLeft = new JList(arr);

lstRight = new JList();

btnAdd = new JButton(">");


this.add(lstLeft);

this.add(btnAdd);

this.add(lstRight);


lstLeft.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

btnAdd.addActionListener(this);

}


public static void main(String[] args) {

new Test();

}


@Override

public void actionPerformed(ActionEvent e) {

Object[] items = lstLeft.getSelectedValues();

DefaultListModel model = new DefaultListModel();

lstRight.setModel(model);

model.removeAllElements();


for(Object value : items) {

model.addElement(value);

}

}

}




運行測試:


Ⅶ java的一個窗體建立

利用Swing 創建一個窗體 -

創建窗體如下代碼:

import
javax.swing.*;

import java.awt.*;

public class WindowsDemo extends JFrame {

public WindowsDemo(String sTitle, int iWidth, int
iHeight) {

Dimension dim =
Toolkit.getDefaultToolkit().getScreenSize();// 獲取屏幕尺寸
ImageIcon ii = new
ImageIcon("images/middle.gif");
setTitle(sTitle);//
設置窗體標題
setIconImage(ii.getImage());//
設置窗體的圖標
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//
設置但關閉窗體時退出程序
setSize(iWidth, iHeight);//
設置窗體大小
int w = getSize().width;//
獲取窗體寬度
int h = getSize().height;//
獲取窗體高度
System.out.println("窗體寬:" + w +
" 窗體高:" + h);
int x = (dim.width - w) /
2;
int y = (dim.height - h) /
2;
setLocation(x, y);//
將窗體移到屏幕中間
setVisible(true);// 顯示窗體
}
public static void main(String[] args)
{
JFrame.(true);//
使用最新的SWING外觀
WindowsDemo wd = new
WindowsDemo("小龍窗口", 400, 300);
}
}

Ⅷ 用java做一個窗口

java做窗口的話,需要用swing技術,之後創建JFrame 等組件,即可完成窗口創建工作。
package inter.frame;import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;public class MenuTest { /**
* @param args
*/
JFrame frame; //定義一個窗口架構
JMenuBar mb;//定義窗口的菜單工具欄
JMenu m; //定義菜單
JMenuItem mi1;//定義菜單的內容
JMenuItem mi2; //定義菜單的內容
public MenuTest() {
initFrame();
initAction();
}
public void initFrame() {
frame = new JFrame();
mb = new JMenuBar();
m = new JMenu("學生查詢");
mi1 = new JMenuItem("確認");
mi2 = new JMenuItem("取消"); m.add(mi1);
m.add(mi2);
mb.add(m);
frame.add(mb, BorderLayout.NORTH);
frame.setSize(300, 300); //設置窗口大小
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設置退出時關閉窗口
frame.setVisible(true);//設置窗口可見
} public void initAction() {
mi1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 具體實現代碼根據實際要求填寫
System.out.println("click");
JOptionPane.showMessageDialog(null, "你點擊了確定按鈕");
}
});
mi2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 具體實現代碼根據實際要求填寫
JOptionPane.showMessageDialog(null, "你點擊了取消按鈕");
}
});
} public static void main(String[] args) {
new MenuTest();//執行菜單創建
}}

Ⅸ Java如何顯示窗體

不太懂你的要求,猜了一下。可能是這樣:
import java.awt.Frame;
import java.awt.TextArea;

public class HelloWorld {
public static void main(String args[]){
Frame frame=new Frame("Windows窗體");
TextArea tArea=new TextArea();
tArea.append("HelloWorld");
frame.add(tArea);
frame.setVisible(true);//顯示窗體
}

}

Ⅹ Java窗體事件

代碼是不完整的,我只能猜測接下來,你有一個注冊的偵聽器的按鈕呢? 在此方法System.out.printf();看起來一定要點擊執行此方法的按鈕。

熱點內容
單片機android 發布:2024-09-20 09:07:24 瀏覽:764
如何提高三星a7安卓版本 發布:2024-09-20 08:42:35 瀏覽:663
如何更換伺服器網站 發布:2024-09-20 08:42:34 瀏覽:310
子彈演算法 發布:2024-09-20 08:41:55 瀏覽:288
手機版網易我的世界伺服器推薦 發布:2024-09-20 08:41:52 瀏覽:816
安卓x7怎麼邊打游戲邊看視頻 發布:2024-09-20 08:41:52 瀏覽:161
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:93
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:506
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:657
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:480