1:設(shè)置一個(gè)boolean變量,響應(yīng)button事件后,
東區(qū)網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),東區(qū)網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為東區(qū)1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的東區(qū)做網(wǎng)站的公司定做!
falg = !falg
if(falg) {
button.setText("click me");
} else {
button.setText("click me again");l
}
2:設(shè)置顏色為黃色,當(dāng)然用你的Grapics,代碼如下:
Grapics g = getGrapics;
g.setCloro(Cloro.(黃色,我不知道怎么拼寫));
g.drawline(int x,int y,int i,int j) //括號(hào)里面有參數(shù),自己查看sdk,我沒環(huán)境,寫不出來(lái)。應(yīng)該是這樣!
g.drawline(int x,int y,int i,int j)
g.drawline(int x,int y,int i,int j)
g.drawline(int x,int y,int i,int j)
g.drawline(int x,int y,int i,int j)
g.drawline(int x,int y,int i,int j)
3:也是通過Grapics來(lái)畫,getGrapics就可以了。
4:沒明白你的意思,應(yīng)該是說(shuō)獲取html里的prarm吧?然后在根據(jù)prarm的值設(shè)置某些東西吧?
getParamXXX() //xxx忘了怎么寫,用IDE就不用記,陰文很爛的。
《英魂之刃》,我是最近聽說(shuō)出了自走棋被我朋友拉過來(lái)一起玩的,一開始玩不懂,不太愛玩后面我朋友教我玩,才發(fā)現(xiàn)原來(lái)挺有趣的,首先是這個(gè)自走棋比刀塔自走棋的時(shí)間短,操作也非常簡(jiǎn)單。游戲使用了獨(dú)創(chuàng)的六邊形棋盤,還原策略戰(zhàn)棋類玩法初始體驗(yàn)的同時(shí),也提升了游戲的策略維度。
這是我剛接觸JAVa時(shí)寫的,想法一樣,可以參考一下。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Shape_page extends WindowAdapter implements ActionListener,ItemListener{
private JFrame frame;
private Panel p,p1,p2;
private JLabel title;
private JCheckBox area,perimeter;
private ButtonGroup bg;
private JRadioButton b,b1,b2;
private ButtonGroup bg1;
boolean isSelect=false;
static String index="";
public Shape_page(){
Font s=new Font("宋體",Font.BOLD,16);
UIManager.put("Label.font",s);
//UIManager.put("JRadioButton.font",s);
UIManager.put("Button.font",s);
frame=new JFrame();
p=new Panel();
p1=new Panel();
p2=new Panel();
title=new JLabel("圖形面積與周長(zhǎng)計(jì)算器");
area=new JCheckBox("面積");
perimeter=new JCheckBox("周長(zhǎng)");
b=new JRadioButton("三角形");
b1=new JRadioButton("圓形");
b2=new JRadioButton("矩形");
b.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
area.addItemListener(this);
perimeter.addItemListener(this);
bg=new ButtonGroup();
bg.add(area);
bg.add(perimeter);
bg1=new ButtonGroup();
bg1.add(b);
bg1.add(b1);
bg1.add(b2);
frame.setLayout(new GridLayout(3,1));
frame.addWindowListener(this);
frame.add(p);
frame.add(p2);
frame.add(p1);
p.add(title);
p1.add(b);
p1.add(b1);
p1.add(b2);
p2.add(area);
p2.add(perimeter);
frame.setSize(300,200);
frame.setVisible(true);
frame.setResizable(false);
}
public void actionPerformed(ActionEvent e){
if(index.isEmpty()){
JOptionPane.showMessageDialog(frame,"必須要先選擇計(jì)算的類型");
return ;
}
String str=e.getActionCommand();
if(str.equals("三角形"))
new Triangle();
else if(str.equals("圓形"))
new Circular();
else if(str.equals("矩形"))
new Rectangle();
}
public void itemStateChanged(ItemEvent e) {
JCheckBox check=(JCheckBox)e.getItem();
String str=check.getText();
if(str.equals("面積"))
index="面積";
else if(str.equals("周長(zhǎng)"))
index="周長(zhǎng)";
}
public void windowsClosing(WindowEvent e){
System.exit(0);
}
public static void main(String[] args) {
new Shape_page();
}
}
abstract class Shape{
public abstract double getArea();
public abstract double Perimeter();
}
class Circular extends Shape implements ActionListener{
private double IP=3.141592654;
private double r;
private JFrame frame;
private Panel p,p1,p2,p3;
private JLabel title,output;
private JLabel jl,jl1;
private JButton right,Cancel;
private JTextField t;
Circular(){
frame=new JFrame();
frame.setLayout(new GridLayout(4,1));
title=new JLabel("圓形"+Shape_page.index+"計(jì)算器");
output=new JLabel("所輸入的圓形的"+Shape_page.index+"為");
right=new JButton("確定");
Cancel=new JButton("取消");
jl=new JLabel("圓的半徑:");
jl1=new JLabel("a");
t=new JTextField(4);
p=new Panel();
p1=new Panel();
p2=new Panel();
p3=new Panel();
p.add(title);p1.add(jl);
p1.add(jl1);p1.add(t);
p2.add(output);p3.add(right);
p3.add(Cancel);
right.addActionListener(this);
Cancel.addActionListener(this);
frame.add(p);
frame.add(p1);
frame.add(p2);
frame.add(p3);
frame.setSize(450,250);
frame.setVisible(true);
frame.setResizable(false);
}
public double getArea(){
return IP*r*r;
}
public double Perimeter(){
return 2*IP*r;
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==right){
r=Double.parseDouble(t.getText());
if(Shape_page.index.equals("面積"))
output.setText("所輸入的形圓的面積為"+String.valueOf(getArea()));
else
output.setText("所輸入的圓形的周長(zhǎng)為"+String.valueOf(Perimeter()));
}
else
t.setText("");
}
}
class Triangle extends Shape implements ActionListener{
private double a1;
private double a2;
private double a3;
private JFrame frame;
private Panel p,p1,p2,p3;
private JLabel title,output;
private JLabel jl,jl1,jl2,jl3;
private JButton right,Cancel;
private JTextField t,t1,t2;
Triangle (){
frame=new JFrame();
frame.setLayout(new GridLayout(4,1));
title=new JLabel("三角形"+Shape_page.index+"計(jì)算器");
output=new JLabel("所輸入的三角形的"+Shape_page.index+"為");
right=new JButton("確定");
Cancel=new JButton("取消");
jl=new JLabel("三角形的三條邊:");
jl1=new JLabel("a");
t=new JTextField(4);
jl2=new JLabel("b");
t1=new JTextField(4);
jl3=new JLabel("c");
t2=new JTextField(4);
p=new Panel();
p1=new Panel();
p2=new Panel();
p3=new Panel();
p.add(title);p1.add(jl);
p1.add(jl1);p1.add(t);
p1.add(jl2);p1.add(t1);
p1.add(jl3);p1.add(t2);
p2.add(output);p3.add(right);
p3.add(Cancel);
right.addActionListener(this);
Cancel.addActionListener(this);
frame.add(p);
frame.add(p1);
frame.add(p2);
frame.add(p3);
frame.setSize(450,250);
frame.setVisible(true);
frame.setResizable(false);
}
public boolean isTriangle(){
if(a1+a2a3a1+a3a2a2+a3a1)
return true;
else
return false;
}
public double getArea(){
double a=(a1+a2+a3)/2.0;
double area=a*(a-a1)*(a-a2)*(a-a3);
return Math.sqrt(area);
}
public double Perimeter(){
if(isTriangle())
return a1+a2+a3;
else
return 0;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==right){
a1=Double.parseDouble(t.getText());
a2=Double.parseDouble(t1.getText());
a3=Double.parseDouble(t2.getText());
if(!isTriangle())
output.setText("所輸入的數(shù)值不能構(gòu)成三角形");
else{
if(Shape_page.index.equals("面積"))
output.setText("所輸入的三角形的面積為"+String.valueOf(getArea()));
else
output.setText("所輸入的三角形的周長(zhǎng)為"+String.valueOf(Perimeter()));
}
}
else{
t.setText("");
t1.setText("");
t2.setText("");
}
}
}
class Rectangle extends Shape implements ActionListener{
private double a1;
private double a2;
private JFrame frame;
private Panel p,p1,p2,p3;
private JLabel title,output;
private JLabel jl,jl1;
private JButton right,Cancel;
private JTextField t,t1;
Rectangle (){
frame=new JFrame();
frame.setLayout(new GridLayout(4,1));
title=new JLabel("矩形形"+Shape_page.index+"計(jì)算器");
output=new JLabel("所輸入的矩形的"+Shape_page.index+"為");
right=new JButton("確定");
Cancel=new JButton("取消");
jl=new JLabel("矩形的長(zhǎng)");
jl1=new JLabel("寬");
t=new JTextField(4);
t1=new JTextField(4);
p=new Panel();
p1=new Panel();
p2=new Panel();
p3=new Panel();
p.add(title);p1.add(jl);
p1.add(t);p1.add(jl1);
p1.add(t1);
p2.add(output);p3.add(right);
p3.add(Cancel);
right.addActionListener(this);
Cancel.addActionListener(this);
frame.add(p);
frame.add(p1);
frame.add(p2);
frame.add(p3);
frame.setSize(450,250);
frame.setVisible(true);
frame.setResizable(false);
}
public double getArea(){
return a1*a2;
}
public double Perimeter(){
return 2*(a1+a2);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==right){
a1=Double.parseDouble(t.getText());
a2=Double.parseDouble(t1.getText());
if(Shape_page.index.equals("面積"))
output.setText("所輸入的矩形的面積為"+String.valueOf(getArea()));
else
output.setText("所輸入的矩形的周長(zhǎng)為"+String.valueOf(Perimeter()));
}
else
t.setText("");
}
}
因?yàn)檎叫?,圓,橢圓求周長(zhǎng)和面積的公式是不一樣的,所以要給他們定義不一樣的方法,具體的計(jì)算就按照求周長(zhǎng)面積公式就行了。排序可以把求出來(lái)的結(jié)果放入數(shù)組中,再用想冒泡排序,快速排序,堆排序,桶排序等排序算法進(jìn)行排序就行了。
用路徑來(lái)畫 一般用GeneralPath類來(lái)實(shí)現(xiàn),給出paintComponent方法的代碼,供參考
protected?void?paintComponent(Graphics?g)?{
super.paintComponent(g);
Graphics2D?g2d?=?(Graphics2D)g;
//正六邊形數(shù)據(jù)
float?r?=?100;?//邊長(zhǎng)
float[]?x1?=?{0, ????0.5f*r,???1.5f*r,???2*r,??????1.5f*r,?0.5f*r};
float[]?y1?=?{0.866f*r,?1.732f*r,?1.732f*r,?0.866f*r,?0, ??0};
g2d.translate(100,?100);
GeneralPath?p?=?new?GeneralPath();
p.moveTo(x1[0],?y1[0]);
for?(int?i?=?1;?i??y1.length;?i++)?{
p.lineTo(x1[i],?y1[i]);
}
p.closePath();
g2d.draw(p);
}