java编程:我想实现一个功能:点击下来菜单一个按钮时,弹出一个对话框
JMenuItemcontact_infos1=newJMenuItem("关于作者");top_contact_infos.add(contact_infos1);点击...
JMenuItem contact_infos1 = new JMenuItem("关于作者");
top_contact_infos.add(contact_infos1);
点击关于作者时出现一个对话框
对话框内容有:QQ号,手机号,分行显示 展开
top_contact_infos.add(contact_infos1);
点击关于作者时出现一个对话框
对话框内容有:QQ号,手机号,分行显示 展开
展开全部
//Test.java 主窗体
import java.awt.BorderLayout;
import java.awt.EventQueue;
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.JPanel;
import javax.swing.border.EmptyBorder;
public class Test extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test frame = new Test();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu mnNewMenu = new JMenu("关于读者");
menuBar.add(mnNewMenu);
JMenuItem mntmNewMenuItem = new JMenuItem("关于作者");
mnNewMenu.add(mntmNewMenuItem);
mntmNewMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new About_Author().setVisible(true);;
}
});
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}
}
//About_Author.java 作者页面信息窗体
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
public class About_Author extends JFrame{
private final JPanel contentPanel = new JPanel();
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
About_Author dialog = new About_Author();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public About_Author() {
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
{
JLabel label = new JLabel("QQ");
label.setBounds(160, 10, 54, 15);
contentPanel.add(label);
}
{
JLabel lblNewLabel = new JLabel("手机");
lblNewLabel.setBounds(160, 59, 54, 15);
contentPanel.add(lblNewLabel);
}
JLabel label = new JLabel("作者");
label.setBounds(160, 107, 54, 15);
contentPanel.add(label);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
}
}
import java.awt.BorderLayout;
import java.awt.EventQueue;
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.JPanel;
import javax.swing.border.EmptyBorder;
public class Test extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test frame = new Test();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu mnNewMenu = new JMenu("关于读者");
menuBar.add(mnNewMenu);
JMenuItem mntmNewMenuItem = new JMenuItem("关于作者");
mnNewMenu.add(mntmNewMenuItem);
mntmNewMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new About_Author().setVisible(true);;
}
});
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}
}
//About_Author.java 作者页面信息窗体
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
public class About_Author extends JFrame{
private final JPanel contentPanel = new JPanel();
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
About_Author dialog = new About_Author();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public About_Author() {
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
{
JLabel label = new JLabel("QQ");
label.setBounds(160, 10, 54, 15);
contentPanel.add(label);
}
{
JLabel lblNewLabel = new JLabel("手机");
lblNewLabel.setBounds(160, 59, 54, 15);
contentPanel.add(lblNewLabel);
}
JLabel label = new JLabel("作者");
label.setBounds(160, 107, 54, 15);
contentPanel.add(label);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
}
}
更多追问追答
追问
你这个到是挺靠谱的,
我看有人有这个append,好像简单的多,你知道怎么用吗?
// contentPane = new JPanel();
。。。
// setContentPane(contentPane);
这段代码,感觉没有用啊,我注释掉后,没有任何影响
追答
?append()函数?连接字符串?
// contentPane = new JPanel();
。。。
// setContentPane(contentPane);
这个创建项目时系统自动添加的。创建一个面板用来添加其它控件,然后设置为窗口面板
如果你要往窗口中添加控件,就要用到它了- contentPane.add();
2016-05-06
展开全部
一个简单的例子。。。。importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;publicclassAextendsJFrame{privateAa;publicJLabellbl1;publicJLabellbl2;publicA(){lbl1=newJLabel("111111111");lbl2=newJLabel("222222222");JButtonbtnTest=newJButton("测试按钮");btnTest.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){newB(a).setVisible(true);}});setLayout(newGridLayout(1,3));add(lbl1);add(lbl2);add(btnTest);setSize(300,70);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);a=this;}publicstaticvoidmain(String[]args){newA().setVisible(true);}}classBextendsJFrame{privateAa;privateJTextFieldtxt1;privateJTextFieldtxt2;publicB(Aaa){a=aa;txt1=newJTextField();txt2=newJTextField();JButtonbtnTest=newJButton("测试按钮");btnTest.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){a.lbl1.setText(txt1.getText());a.lbl2.setText(txt2.getText());}});setLayout(newGridLayout(3,1));add(txt1);add(txt2);add(btnTest);setBounds(100,100,300,100);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}}===============有问题直接在这提问吧,说的清楚点就行了。我不要悬赏分
追问
不这是抄的啊
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
jQuery可以实现你的需求
追问
你随便写几行,我参考下行不
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询