java窗体
Ⅰ 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();看起来一定要点击执行此方法的按钮。