java编程包含一个标签和一个按钮,单击按钮时,标签的内容在“你好”和“再见”之间切换。
展开全部
用jquery做
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.4.3.js"></script>
<script type="text/javascript">
$(function(){
$('#a1').toggle(function(){
$("#d1").html("<h1>你好</h1>");
},function(){
$("#d1").html("<h1>再见</h1>");
});
});
</script>
</head>
<body>
<div id="d1"
style="border: black solid 1px; height: 100px; width: 100px;"></div>
<input type="button" value="CLICK ME" id="a1" />
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.4.3.js"></script>
<script type="text/javascript">
$(function(){
$('#a1').toggle(function(){
$("#d1").html("<h1>你好</h1>");
},function(){
$("#d1").html("<h1>再见</h1>");
});
});
</script>
</head>
<body>
<div id="d1"
style="border: black solid 1px; height: 100px; width: 100px;"></div>
<input type="button" value="CLICK ME" id="a1" />
</body>
</html>
展开全部
package example;
import java.awt.BorderLayout;
public class Switch extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Switch frame = new Switch();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Switch() {
final String string = "你好";
final String string2 = "再见";
setTitle("\u5207\u6362\u6807\u7B7E\u5185\u5BB9");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
final JLabel label = new JLabel(string);
label.setFont(new Font("宋体",Font.BOLD,25));
JButton button = new JButton("\u786E\u5B9A");
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (label.getText().equals(string)) {
label.setText(string2);
}
else if (label.getText().equals(string2)) {
label.setText(string);
}
}
});
GroupLayout groupLayout = new GroupLayout(contentPane);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(153, 153, 153)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(button)
.addComponent(label))
.addContainerGap(222, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(label)
.addGap(38, 38, 38)
.addComponent(button)
.addContainerGap(100, Short.MAX_VALUE))
);
contentPane.setLayout(groupLayout);
}
}
import java.awt.BorderLayout;
public class Switch extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Switch frame = new Switch();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Switch() {
final String string = "你好";
final String string2 = "再见";
setTitle("\u5207\u6362\u6807\u7B7E\u5185\u5BB9");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
final JLabel label = new JLabel(string);
label.setFont(new Font("宋体",Font.BOLD,25));
JButton button = new JButton("\u786E\u5B9A");
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (label.getText().equals(string)) {
label.setText(string2);
}
else if (label.getText().equals(string2)) {
label.setText(string);
}
}
});
GroupLayout groupLayout = new GroupLayout(contentPane);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(153, 153, 153)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(button)
.addComponent(label))
.addContainerGap(222, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(label)
.addGap(38, 38, 38)
.addComponent(button)
.addContainerGap(100, Short.MAX_VALUE))
);
contentPane.setLayout(groupLayout);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询