/**
*
*/
package com.window;import java.awt.Container;
import java.awt.Insets;
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.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;/**
* @author .
*
*/
public class DoWindow extends JFrame {
Toolkit tool = Toolkit.getDefaultToolkit();
JMenuBar menu = new JMenuBar();
JMenu choice = new JMenu("选项");
JMenuItem user = new JMenuItem("用户信息");
JMenuItem toLogin = new JMenuItem("重新登陆");
JMenuItem exit = new JMenuItem("退出");
JButton button1 = new JButton("基础信息管理");
JButton button2 = new JButton("进货管理");
JButton button3 = new JButton("销售管理");
JButton button4 = new JButton("查询管理");
JButton button5 = new JButton("库存管理");
JButton button6 = new JButton("系统管理"); public DoWindow(String s) {
//System.gc();
final int width = (int) tool.getScreenSize().getWidth();
final int height = (int) tool.getScreenSize().getHeight();
// 取消布局
setLayout(null);
Container container = getContentPane();
// 使窗口出现在屏幕中心
setBounds((width - 421) / 2, (height - 600) / 2, 421, 600);
// 功能一的按钮属性
button1.setBounds(80, 340, 121, 58);
// 功能二的按钮属性
button2.setBounds(80, 410, 121, 58);
// 功能三的按钮属性
button3.setBounds(80, 480, 121, 58);
// 功能四的按钮属性
button4.setBounds(220, 340, 121, 58);
// 功能五的按钮属性
button5.setBounds(220, 410, 121, 58);
// 功能六的按钮属性
button6.setBounds(220, 480, 121, 58);
// 菜单
menu.setToolTipText("您可以通过打开菜单进行更多操作");
menu.add(choice);
choice.add(user);
// 返回登陆管理系统界面的功能
choice.add(toLogin);
toLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new LoginSystem();
dispose();
}
});
// 退出功能
choice.add(exit);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
setJMenuBar(menu);
// 容器添加组件
container.add(menu);
container.add(button1);
container.add(button2);
container.add(button3);
container.add(button4);
container.add(button5);
container.add(button6);
// 设置窗口可见
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// 设置不同权限的差异性表现
if (s.equals("Limited")) {
button6.setEnabled(false);
JOptionPane.showMessageDialog(null, "您是受限用户,不能对系统进行操作!");
} else if (s.equals("All")) {
JOptionPane.showMessageDialog(null, "您是管理员用户,拥有所有的功能!");
}
}
public static void main(String[] args) {
new DoWindow("All");
}
}如图,加了菜单栏后y的边界就变了
试了各种办法都没用,求解答..JMenuBar
*
*/
package com.window;import java.awt.Container;
import java.awt.Insets;
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.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;/**
* @author .
*
*/
public class DoWindow extends JFrame {
Toolkit tool = Toolkit.getDefaultToolkit();
JMenuBar menu = new JMenuBar();
JMenu choice = new JMenu("选项");
JMenuItem user = new JMenuItem("用户信息");
JMenuItem toLogin = new JMenuItem("重新登陆");
JMenuItem exit = new JMenuItem("退出");
JButton button1 = new JButton("基础信息管理");
JButton button2 = new JButton("进货管理");
JButton button3 = new JButton("销售管理");
JButton button4 = new JButton("查询管理");
JButton button5 = new JButton("库存管理");
JButton button6 = new JButton("系统管理"); public DoWindow(String s) {
//System.gc();
final int width = (int) tool.getScreenSize().getWidth();
final int height = (int) tool.getScreenSize().getHeight();
// 取消布局
setLayout(null);
Container container = getContentPane();
// 使窗口出现在屏幕中心
setBounds((width - 421) / 2, (height - 600) / 2, 421, 600);
// 功能一的按钮属性
button1.setBounds(80, 340, 121, 58);
// 功能二的按钮属性
button2.setBounds(80, 410, 121, 58);
// 功能三的按钮属性
button3.setBounds(80, 480, 121, 58);
// 功能四的按钮属性
button4.setBounds(220, 340, 121, 58);
// 功能五的按钮属性
button5.setBounds(220, 410, 121, 58);
// 功能六的按钮属性
button6.setBounds(220, 480, 121, 58);
// 菜单
menu.setToolTipText("您可以通过打开菜单进行更多操作");
menu.add(choice);
choice.add(user);
// 返回登陆管理系统界面的功能
choice.add(toLogin);
toLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new LoginSystem();
dispose();
}
});
// 退出功能
choice.add(exit);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
setJMenuBar(menu);
// 容器添加组件
container.add(menu);
container.add(button1);
container.add(button2);
container.add(button3);
container.add(button4);
container.add(button5);
container.add(button6);
// 设置窗口可见
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// 设置不同权限的差异性表现
if (s.equals("Limited")) {
button6.setEnabled(false);
JOptionPane.showMessageDialog(null, "您是受限用户,不能对系统进行操作!");
} else if (s.equals("All")) {
JOptionPane.showMessageDialog(null, "您是管理员用户,拥有所有的功能!");
}
}
public static void main(String[] args) {
new DoWindow("All");
}
}如图,加了菜单栏后y的边界就变了
试了各种办法都没用,求解答..JMenuBar
*
*/import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;/**
* @author .
*
*/
public class DoWindow extends JFrame {
Toolkit tool = Toolkit.getDefaultToolkit();
JMenuBar menu = new JMenuBar();
JMenu choice = new JMenu("选项");
JMenuItem user = new JMenuItem("用户信息");
JMenuItem toLogin = new JMenuItem("重新登陆");
JMenuItem exit = new JMenuItem("退出");
JButton button1 = new JButton("基础信息管理");
JButton button2 = new JButton("进货管理");
JButton button3 = new JButton("销售管理");
JButton button4 = new JButton("查询管理");
JButton button5 = new JButton("库存管理");
JButton button6 = new JButton("系统管理"); public DoWindow(String s) {
//System.gc();
final int width = (int) tool.getScreenSize().getWidth();
final int height = (int) tool.getScreenSize().getHeight();
// 取消布局
// setLayout(null);
Container container = getContentPane();
GridLayout gLayout = new GridLayout(2,3,50,50);
container.setLayout(gLayout);
// // 菜单
menu.setToolTipText("您可以通过打开菜单进行更多操作");
menu.add(choice);
choice.add(user);
// 返回登陆管理系统界面的功能
choice.add(toLogin);
toLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// new LoginSystem();
dispose();
}
});
// 退出功能
choice.add(exit);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
setJMenuBar(menu);
// 容器添加组件
container.add(button1);
container.add(button2);
container.add(button3);
container.add(button4);
container.add(button5);
container.add(button6);
//
setPreferredSize(new Dimension(500,500));
// 使窗口出现在屏幕中心
setLocationRelativeTo(null);
pack();
// 设置窗口可见
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// 设置不同权限的差异性表现
if (s.equals("Limited")) {
button6.setEnabled(false);
JOptionPane.showMessageDialog(null, "您是受限用户,不能对系统进行操作!");
} else if (s.equals("All")) {
JOptionPane.showMessageDialog(null, "您是管理员用户,拥有所有的功能!");
}
}
public static void main(String[] args) {
new DoWindow("All");
}
}
container.add(menu);