JAVA题,请各位牛人帮帮忙!
创建一个应用程序,图形用户界面,上面有三个单选按钮(学习,工作,娱乐),当单击某个单选钮选项时会打开一个相对应的窗口(如点击学习按钮会出现一个新的窗口,上面标题是点击学习...
创建一个应用程序,图形用户界面,上面有三个单选按钮(学习,工作,娱乐),当单击某个单选钮选项时会打开一个相对应的窗口(如点击学习按钮会出现一个新的窗口,上面标题是点击学习选项,标签是学习)
展开
5个回答
展开全部
要用到 对话框组建,你可以找下 ,有关对话框的帮助文档,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是够简单的,最普通的按钮事件么,查一下出就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你找一下API就知道了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
文件一,文件名Application2.java,这个文件不用管用JBuilder建工程时候工具会帮你建立。
package db;
import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;
public class Application2 {
boolean packFrame = false;
/**
* Construct and show the application.
*/
public Application2() {
Frame3 frame = new Frame3();
// Validate frames that have preset sizes
// Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
} else {
frame.validate();
}
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
/**
* Application entry point.
*
* @param args String[]
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
}
new Application2();
}
});
}
}
文件二 文件名Frame3.java
package db;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame3 extends JFrame {
JPanel contentPane;
JRadioButton jRadioButton1 = new JRadioButton();
public Frame3() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jRadioButton1.setText("学习标签");
jRadioButton1.setBounds(new Rectangle(74, 47, 251, 30));
jRadioButton1.addActionListener(new Frame3_jRadioButton1_actionAdapter(this));
contentPane.add(jRadioButton1);
}
public void jRadioButton1_actionPerformed(ActionEvent e) {
if(jRadioButton1.isSelected()){//判断单选按钮是否被选中,选中为真,未选中为假
Frame4 J=new Frame4();
J.setTitle("学习标签");//设置标题
J.setSize(new Dimension(400,300));//设置大小
J.show();//填出窗体.
}
}
}
class Frame3_jRadioButton1_actionAdapter implements ActionListener {
private Frame3 adaptee;
Frame3_jRadioButton1_actionAdapter(Frame3 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jRadioButton1_actionPerformed(e);
}
}
文件3文件名Frame4.java
package db;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame4 extends JFrame {
JButton jButton1 = new JButton();
public Frame4() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jButton1.setBounds(new Rectangle(10, 143, 338, 52));
jButton1.setText("欢迎光临,点击按钮退出");
jButton1.addActionListener(new Frame4_jButton1_actionAdapter(this));
this.getContentPane().add(jButton1, null);
}
public void jButton1_actionPerformed(ActionEvent e) {
System.exit(1);
}
}
class Frame4_jButton1_actionAdapter implements ActionListener {
private Frame4 adaptee;
Frame4_jButton1_actionAdapter(Frame4 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
把这三个文件放在同一个文件夹下从后往前编译,执行Application2就可以了。
package db;
import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;
public class Application2 {
boolean packFrame = false;
/**
* Construct and show the application.
*/
public Application2() {
Frame3 frame = new Frame3();
// Validate frames that have preset sizes
// Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
} else {
frame.validate();
}
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
/**
* Application entry point.
*
* @param args String[]
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
}
new Application2();
}
});
}
}
文件二 文件名Frame3.java
package db;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame3 extends JFrame {
JPanel contentPane;
JRadioButton jRadioButton1 = new JRadioButton();
public Frame3() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jRadioButton1.setText("学习标签");
jRadioButton1.setBounds(new Rectangle(74, 47, 251, 30));
jRadioButton1.addActionListener(new Frame3_jRadioButton1_actionAdapter(this));
contentPane.add(jRadioButton1);
}
public void jRadioButton1_actionPerformed(ActionEvent e) {
if(jRadioButton1.isSelected()){//判断单选按钮是否被选中,选中为真,未选中为假
Frame4 J=new Frame4();
J.setTitle("学习标签");//设置标题
J.setSize(new Dimension(400,300));//设置大小
J.show();//填出窗体.
}
}
}
class Frame3_jRadioButton1_actionAdapter implements ActionListener {
private Frame3 adaptee;
Frame3_jRadioButton1_actionAdapter(Frame3 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jRadioButton1_actionPerformed(e);
}
}
文件3文件名Frame4.java
package db;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Frame4 extends JFrame {
JButton jButton1 = new JButton();
public Frame4() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jButton1.setBounds(new Rectangle(10, 143, 338, 52));
jButton1.setText("欢迎光临,点击按钮退出");
jButton1.addActionListener(new Frame4_jButton1_actionAdapter(this));
this.getContentPane().add(jButton1, null);
}
public void jButton1_actionPerformed(ActionEvent e) {
System.exit(1);
}
}
class Frame4_jButton1_actionAdapter implements ActionListener {
private Frame4 adaptee;
Frame4_jButton1_actionAdapter(Frame4 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
把这三个文件放在同一个文件夹下从后往前编译,执行Application2就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询