- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在学校学习 Java,所以我做了一些任务,但我希望能够从中制作一个可执行文件,这样我就可以将它发送给一些 friend 来展示我制作的东西。我在这个网站上发现你必须使用 JFrames 和类似的东西,但我不知道它是如何工作的。对此做了一些研究,但我找不到一种简单的方法来转换它而不重做我几乎所有的代码。我的代码在下面,有人可以帮我吗?
企业
package jpr_keuze;
import java.applet.*;
import java.awt.*;
public class Keuze extends Applet {
Choice kleur, vorm;
Label titel, lblKleur, lblVorm, parameters, lblParameter1, lblParameter2, lblParameter3, lblParameter4, lblParameter5, lblParameter6;
TextField parameter1, parameter2, parameter3, parameter4, parameter5, parameter6, tekst;
Button teken, vergrendel1, vergrendel2;
Integer intParameter1, intParameter2, intParameter3, intParameter4, intParameter5, intParameter6, x, y, lengte, grootsteX, grootsteY, kleinsteX, kleinsteY, intParameter7, intParameter8, intParameter9, intParameter10, intParameter11, intParameter12, intVorm, intKleur, intParameter13, intParameter14, intParameter15, intParameter16, intParameter17, intParameter18, intKleur2, intVorm2;
Boolean draw, draw2, draw3;
Polygon driehoek, driehoek2, driehoek3;
String strTekst, strTekst2, strTekst3;
public void init(){
draw = false;
draw2 = false;
draw3 = false;
kleur = new Choice();
vorm = new Choice();
titel = new Label("Objecten tekenen");
lblKleur = new Label("Kies een kleur: ");
lblVorm = new Label("Kies een vorm: ");
parameters = new Label("Parameters");
parameter1 = new TextField("1");
parameter2 = new TextField("1");
parameter3 = new TextField("1");
parameter4 = new TextField("1");
parameter5 = new TextField("1");
parameter6 = new TextField("1");
teken = new Button("Teken de gekleurde vorm");
driehoek = new Polygon();
tekst = new TextField();
lblParameter1 = new Label();
lblParameter2 = new Label();
lblParameter3 = new Label();
lblParameter4 = new Label();
lblParameter5 = new Label();
lblParameter6 = new Label();
vergrendel1 = new Button("Vergrendel 1");
vergrendel2 = new Button("Vergrendel 2");
driehoek2 = new Polygon();
driehoek3 = new Polygon();
add(kleur);
add(vorm);
add(titel);
add(lblKleur);
add(lblVorm);
add(parameters);
add(parameter1);
add(parameter2);
add(parameter3);
add(parameter4);
add(parameter5);
add(parameter6);
add(teken);
add(tekst);
add(lblParameter1);
add(lblParameter2);
add(lblParameter3);
add(lblParameter4);
add(lblParameter5);
add(lblParameter6);
add(vergrendel1);
add(vergrendel2);
kleur.add("Rood");//0
kleur.add("Groen");//1
kleur.add("Blauw");//2
kleur.add("Oranje");//3
kleur.add("Lichtblauw");//4
kleur.add("Geel");//5
kleur.add("Zwart");//6
kleur.add("Wit");//7
kleur.add("Roze");//8
kleur.add("Magenta");//9
vorm.add("Lijnstuk");//0
vorm.add("Rechthoek");//1
vorm.add("Ovaal");//2
vorm.add("Driehoek");//3
vorm.add("Rechthoek met afgeronde hoeken");//4
vergrendel1.setBackground(Color.green);
vergrendel2.setBackground(Color.green);
}
public void paint(Graphics g){
setSize(750,750);
intParameter1 = Integer.parseInt(parameter1.getText());
intParameter2 = Integer.parseInt(parameter2.getText());
intParameter3 = Integer.parseInt(parameter3.getText());
intParameter4 = Integer.parseInt(parameter4.getText());
intParameter5 = Integer.parseInt(parameter5.getText());
intParameter6 = Integer.parseInt(parameter6.getText());
strTekst = tekst.getText();
grootsteX = 0;
grootsteY = 0;
kleinsteX = 0;
kleinsteY = 0;
setBackground(Color.lightGray);
lblKleur.setBackground(Color.lightGray);
lblVorm.setBackground(Color.lightGray);
parameters.setBackground(Color.lightGray);
teken.setBackground(Color.cyan);
titel.setBackground(Color.red);
titel.setBounds(0, 0, 750, 25);
titel.setAlignment(Label.CENTER);
lblParameter1.setBackground(Color.lightGray);
lblParameter2.setBackground(Color.lightGray);
lblParameter3.setBackground(Color.lightGray);
lblParameter4.setBackground(Color.lightGray);
lblParameter5.setBackground(Color.lightGray);
lblParameter6.setBackground(Color.lightGray);
lblKleur.setBounds(150, 50, 100, 25);
lblVorm.setBounds(150, 75, 100, 25);
parameters.setBounds(150, 105, 100, 25);
kleur.setBounds(250, 50, 100, 25);
vorm.setBounds(250, 75, 250, 25);
parameter1.setBounds(370, 105, 50, 20);
parameter2.setBounds(550, 105, 50 ,20);
parameter3.setBounds(370, 130, 50, 20);
parameter4.setBounds(550, 130, 50, 20);
parameter5.setBounds(370, 155, 50, 20);
parameter6.setBounds(550, 155, 50, 20);
teken.setBounds(250, 230, 200, 25);
tekst.setBounds(250, 190, 200, 20);
lblParameter1.setBounds(250, 105, 120, 20);
lblParameter2.setBounds(430, 105, 120, 20);
lblParameter3.setBounds(250, 130, 120, 20);
lblParameter4.setBounds(430, 130, 120, 20);
lblParameter5.setBounds(250, 155, 120, 20);
lblParameter6.setBounds(430, 155, 120, 20);
vergrendel1.setBounds(0, 230, 200, 25);
vergrendel2.setBounds(500, 230, 200, 25);
lblParameter1.setText("X1: ");
lblParameter2.setText("Y1: ");
lblParameter1.setAlignment(Label.RIGHT);
lblParameter2.setAlignment(Label.RIGHT);
lblParameter3.setAlignment(Label.RIGHT);
lblParameter4.setAlignment(Label.RIGHT);
lblParameter5.setAlignment(Label.RIGHT);
lblParameter6.setAlignment(Label.RIGHT);
driehoek.reset();
driehoek2.reset();
driehoek3.reset();
if (draw == true){
switch (kleur.getSelectedIndex()){
case 0: g.setColor(Color.red);
break;
case 1: g.setColor(Color.green);
break;
case 2: g.setColor(Color.blue);
break;
case 3: g.setColor(Color.orange);
break;
case 4: g.setColor(Color.cyan);
break;
case 5: g.setColor(Color.yellow);
break;
case 6: g.setColor(Color.black);
break;
case 7: g.setColor(Color.white);
break;
case 8: g.setColor(Color.pink);
break;
case 9: g.setColor(Color.magenta);
break;
}
switch (vorm.getSelectedIndex()){
case 0: g.drawLine(intParameter1, intParameter2, intParameter3, intParameter4);
g.setColor(Color.darkGray);
g.drawString(intParameter1 + " , " + intParameter2, intParameter1 - 5, intParameter2 - 5);
g.drawString(intParameter3 + " , " + intParameter4, intParameter3 + 5, intParameter4 - 5);
grootsteX = intParameter1;
kleinsteX = intParameter3;
if (intParameter3>grootsteX){
grootsteX = intParameter3;
kleinsteX = intParameter1;
}
grootsteY = intParameter2;
kleinsteY = intParameter4;
if (intParameter4>grootsteY){
grootsteY = intParameter4;
kleinsteY = intParameter2;
}
x = kleinsteX + (grootsteX - kleinsteX)/2;
y = kleinsteY + (grootsteY - kleinsteY)/2;
break;
case 1: g.fillRect(intParameter1, intParameter2, intParameter3, intParameter4);
g.setColor(Color.darkGray);
g.drawString(intParameter1 + " , " + intParameter2, intParameter1 - 5, intParameter2 - 5);
g.drawString(intParameter3.toString(), intParameter1 + intParameter3 /2, intParameter2 + intParameter4 + 25);
g.drawString(intParameter4.toString(), intParameter1 + intParameter3 + 5, intParameter2 + intParameter4 /2);
x = intParameter1 + (intParameter3 / 2);
y = intParameter2 + (intParameter4 / 2);
break;
case 2: g.fillOval(intParameter1, intParameter2, intParameter3, intParameter4);
g.setColor(Color.darkGray);
g.drawString(intParameter1 + " , " + intParameter2, intParameter1-25, intParameter2 - 25);
g.drawString(intParameter3.toString(), intParameter1 + intParameter3/2, intParameter2 + intParameter4 + 25);
g.drawString(intParameter4.toString(), intParameter1 + intParameter3 + 5, intParameter2 + intParameter4/2);
x = intParameter1 + (intParameter3 / 2);
y = intParameter2 + (intParameter4 / 2);
break;
case 3: driehoek.addPoint(intParameter1, intParameter2);
driehoek.addPoint(intParameter3, intParameter4);
driehoek.addPoint(intParameter5, intParameter6);
g.fillPolygon(driehoek);
grootsteX = intParameter1;
if (intParameter3>grootsteX)
grootsteX = intParameter3;
if (intParameter5>grootsteX)
grootsteX = intParameter5;
kleinsteX = intParameter1;
if (intParameter3<kleinsteX)
kleinsteX = intParameter3;
if (intParameter5<kleinsteX)
kleinsteX = intParameter5;
grootsteY = intParameter2;
if (intParameter4>grootsteY)
grootsteY = intParameter4;
if (intParameter6>grootsteY)
grootsteY = intParameter6;
kleinsteY = intParameter2;
if(intParameter4<kleinsteY)
kleinsteY = intParameter4;
if(intParameter6<kleinsteY)
kleinsteY = intParameter6;
x = kleinsteX + (grootsteX - kleinsteX)/2;
y = kleinsteY + (grootsteY - kleinsteY)/2;
g.setColor(Color.darkGray);
g.drawString(intParameter1 + " , " + intParameter2, intParameter1 - 25, intParameter2 - 25);
g.drawString(intParameter3 + " , " + intParameter4, intParameter3 - 25, intParameter4 - 25);
g.drawString(intParameter5 + " , " + intParameter6, intParameter5 - 10, intParameter6 - 25);
break;
case 4: g.fillRoundRect(intParameter1, intParameter2, intParameter3, intParameter4, intParameter5, intParameter6);
x = intParameter1 + (intParameter3 / 2);
y = intParameter2 + (intParameter4 / 2);
g.setColor(Color.darkGray);
g.drawString(intParameter1 + " , " + intParameter2, intParameter1 - 5, intParameter2 - 10);
g.drawString(intParameter3.toString(), intParameter1 + intParameter3 /2, intParameter2 + intParameter4 + 25);
g.drawString(intParameter4.toString(), intParameter1 + intParameter3 + 5, intParameter2 + intParameter4 /2);
g.drawString(intParameter5.toString(), intParameter1 + 30, intParameter2 + 15);
g.drawString(intParameter6.toString(), intParameter1 + 15, intParameter2 + 30);
break;
}
g.setColor(Color.darkGray);
lengte = (strTekst.length() * 5)/2;
g.drawString(strTekst, x - lengte, y);
}
switch(vorm.getSelectedIndex()){
case 0: lblParameter3.setText("X2: ");
lblParameter4.setText("Y2: ");
lblParameter5.setText("");
lblParameter6.setText("");
parameter5.setVisible(false);
parameter6.setVisible(false);
break;
case 1: lblParameter3.setText("Breedte: ");
lblParameter4.setText("Hoogte: ");
lblParameter5.setText("");
lblParameter6.setText("");
parameter5.setVisible(false);
parameter6.setVisible(false);
break;
case 2: lblParameter3.setText("Breedte: ");
lblParameter4.setText("Hoogte: ");
lblParameter5.setText("");
lblParameter6.setText("");
parameter5.setVisible(false);
parameter6.setVisible(false);
break;
case 3: lblParameter3.setText("X2: ");
lblParameter4.setText("Y2: ");
lblParameter5.setText("X3: ");
lblParameter6.setText("Y3: ");
parameter5.setVisible(true);
parameter6.setVisible(true);
case 4: lblParameter3.setText("Breedte: ");
lblParameter4.setText("Hoogte: ");
lblParameter5.setText("Breedte ronde hoek: ");
lblParameter6.setText("Hoogte ronde hoek: ");
parameter5.setVisible(true);
parameter6.setVisible(true);
break;
}
draw = false;
if (draw2 == true){
switch (intKleur){
case 0: g.setColor(Color.red);
break;
case 1: g.setColor(Color.green);
break;
case 2: g.setColor(Color.blue);
break;
case 3: g.setColor(Color.orange);
break;
case 4: g.setColor(Color.cyan);
break;
case 5: g.setColor(Color.yellow);
break;
case 6: g.setColor(Color.black);
break;
case 7: g.setColor(Color.white);
break;
case 8: g.setColor(Color.pink);
break;
case 9: g.setColor(Color.magenta);
break;
}
switch (intVorm){
case 0: g.drawLine(intParameter7, intParameter8, intParameter9, intParameter10);
g.setColor(Color.darkGray);
g.drawString(intParameter7 + " , " + intParameter8, intParameter7 - 5, intParameter8 - 5);
g.drawString(intParameter9 + " , " + intParameter10, intParameter9 + 5, intParameter10 - 5);
grootsteX = intParameter7;
kleinsteX = intParameter9;
if (intParameter9>grootsteX){
grootsteX = intParameter9;
kleinsteX = intParameter7;
}
grootsteY = intParameter8;
kleinsteY = intParameter10;
if (intParameter10>grootsteY){
grootsteY = intParameter10;
kleinsteY = intParameter8;
}
x = kleinsteX + (grootsteX - kleinsteX)/2;
y = kleinsteY + (grootsteY - kleinsteY)/2;
break;
case 1: g.fillRect(intParameter7, intParameter8, intParameter9, intParameter10);
g.setColor(Color.darkGray);
g.drawString(intParameter7 + " , " + intParameter8, intParameter7 - 5, intParameter8 - 5);
g.drawString(intParameter9.toString(), intParameter7 + intParameter9 /2, intParameter7 + intParameter10 + 25);
g.drawString(intParameter10.toString(), intParameter7 + intParameter9 + 5, intParameter8 + intParameter10 /2);
x = intParameter7 + (intParameter9 / 2);
y = intParameter8 + (intParameter10 / 2);
break;
case 2: g.fillOval(intParameter7, intParameter8, intParameter9, intParameter10);
g.setColor(Color.darkGray);
g.drawString(intParameter7 + " , " + intParameter8, intParameter7-25, intParameter8 - 25);
g.drawString(intParameter9.toString(), intParameter7 + intParameter9/2, intParameter8 + intParameter10 + 25);
g.drawString(intParameter10.toString(), intParameter7 + intParameter9 + 5, intParameter8 + intParameter10/2);
x = intParameter7 + (intParameter9 / 2);
y = intParameter8 + (intParameter10 / 2);
break;
case 3: driehoek2.addPoint(intParameter7, intParameter8);
driehoek2.addPoint(intParameter9, intParameter10);
driehoek2.addPoint(intParameter11, intParameter12);
g.fillPolygon(driehoek2);
grootsteX = intParameter7;
if (intParameter9>grootsteX)
grootsteX = intParameter9;
if (intParameter11>grootsteX)
grootsteX = intParameter11;
kleinsteX = intParameter7;
if (intParameter9<kleinsteX)
kleinsteX = intParameter9;
if (intParameter11<kleinsteX)
kleinsteX = intParameter11;
grootsteY = intParameter8;
if (intParameter10>grootsteY)
grootsteY = intParameter10;
if (intParameter12>grootsteY)
grootsteY = intParameter12;
kleinsteY = intParameter8;
if(intParameter10<kleinsteY)
kleinsteY = intParameter10;
if(intParameter12<kleinsteY)
kleinsteY = intParameter12;
x = kleinsteX + (grootsteX - kleinsteX)/2;
y = kleinsteY + (grootsteY - kleinsteY)/2;
g.setColor(Color.darkGray);
g.drawString(intParameter7 + " , " + intParameter8, intParameter7 - 25, intParameter8 - 25);
g.drawString(intParameter9 + " , " + intParameter10, intParameter9 - 25, intParameter10 - 25);
g.drawString(intParameter11 + " , " + intParameter12, intParameter11 - 10, intParameter12 - 25);
break;
case 4: g.fillRoundRect(intParameter7, intParameter8, intParameter9, intParameter10, intParameter11, intParameter12);
x = intParameter7 + (intParameter9 / 2);
y = intParameter8 + (intParameter10 / 2);
g.setColor(Color.darkGray);
g.drawString(intParameter7 + " , " + intParameter8, intParameter7 - 5, intParameter8 - 10);
g.drawString(intParameter9.toString(), intParameter7 + intParameter9 /2, intParameter8 + intParameter10 + 25);
g.drawString(intParameter10.toString(), intParameter7 + intParameter9 + 5, intParameter8 + intParameter10 /2);
g.drawString(intParameter11.toString(), intParameter7 + 30, intParameter8 + 15);
g.drawString(intParameter12.toString(), intParameter7 + 15, intParameter8 + 30);
break;
}
g.setColor(Color.darkGray);
lengte = (strTekst2.length() * 5)/2;
g.drawString(strTekst2, x - lengte, y);
}
if (draw3 == true){
switch (intKleur2){
case 0: g.setColor(Color.red);
break;
case 1: g.setColor(Color.green);
break;
case 2: g.setColor(Color.blue);
break;
case 3: g.setColor(Color.orange);
break;
case 4: g.setColor(Color.cyan);
break;
case 5: g.setColor(Color.yellow);
break;
case 6: g.setColor(Color.black);
break;
case 7: g.setColor(Color.white);
break;
case 8: g.setColor(Color.pink);
break;
case 9: g.setColor(Color.magenta);
break;
}
switch (intVorm2){
case 0: g.drawLine(intParameter13, intParameter14, intParameter15, intParameter16);
g.setColor(Color.darkGray);
g.drawString(intParameter13 + " , " + intParameter14, intParameter13 - 5, intParameter14 - 5);
g.drawString(intParameter15 + " , " + intParameter16, intParameter15 + 5, intParameter16 - 5);
grootsteX = intParameter13;
kleinsteX = intParameter15;
if (intParameter15>grootsteX){
grootsteX = intParameter15;
kleinsteX = intParameter13;
}
grootsteY = intParameter14;
kleinsteY = intParameter16;
if (intParameter16>grootsteY){
grootsteY = intParameter16;
kleinsteY = intParameter14;
}
x = kleinsteX + (grootsteX - kleinsteX)/2;
y = kleinsteY + (grootsteY - kleinsteY)/2;
break;
case 1: g.fillRect(intParameter13, intParameter14, intParameter15, intParameter16);
g.setColor(Color.darkGray);
g.drawString(intParameter13 + " , " + intParameter14, intParameter13 - 5, intParameter14 - 5);
g.drawString(intParameter15.toString(), intParameter13 + intParameter15 /2, intParameter13 + intParameter16 + 25);
g.drawString(intParameter16.toString(), intParameter13 + intParameter15 + 5, intParameter14 + intParameter16 /2);
x = intParameter7 + (intParameter15 / 2);
y = intParameter8 + (intParameter16 / 2);
break;
case 2: g.fillOval(intParameter13, intParameter14, intParameter15, intParameter16);
g.setColor(Color.darkGray);
g.drawString(intParameter13 + " , " + intParameter14, intParameter13-25, intParameter14 - 25);
g.drawString(intParameter15.toString(), intParameter13 + intParameter15/2, intParameter14 + intParameter16 + 25);
g.drawString(intParameter16.toString(), intParameter13 + intParameter15 + 5, intParameter14 + intParameter16/2);
x = intParameter13 + (intParameter15 / 2);
y = intParameter14 + (intParameter16 / 2);
break;
case 3: driehoek3.addPoint(intParameter13, intParameter14);
driehoek3.addPoint(intParameter15, intParameter16);
driehoek3.addPoint(intParameter17, intParameter18);
g.fillPolygon(driehoek3);
grootsteX = intParameter13;
if (intParameter15>grootsteX)
grootsteX = intParameter15;
if (intParameter17>grootsteX)
grootsteX = intParameter17;
kleinsteX = intParameter13;
if (intParameter15<kleinsteX)
kleinsteX = intParameter15;
if (intParameter17<kleinsteX)
kleinsteX = intParameter17;
grootsteY = intParameter14;
if (intParameter16>grootsteY)
grootsteY = intParameter16;
if (intParameter18>grootsteY)
grootsteY = intParameter18;
kleinsteY = intParameter14;
if(intParameter16<kleinsteY)
kleinsteY = intParameter16;
if(intParameter18<kleinsteY)
kleinsteY = intParameter18;
x = kleinsteX + (grootsteX - kleinsteX)/2;
y = kleinsteY + (grootsteY - kleinsteY)/2;
g.setColor(Color.darkGray);
g.drawString(intParameter13 + " , " + intParameter14, intParameter13 - 25, intParameter14 - 25);
g.drawString(intParameter15 + " , " + intParameter16, intParameter15 - 25, intParameter16 - 25);
g.drawString(intParameter17 + " , " + intParameter18, intParameter17 - 10, intParameter18 - 25);
break;
case 4: g.fillRoundRect(intParameter13, intParameter14, intParameter5, intParameter16, intParameter17, intParameter18);
x = intParameter13 + (intParameter15 / 2);
y = intParameter14 + (intParameter16 / 2);
g.setColor(Color.darkGray);
g.drawString(intParameter13 + " , " + intParameter14, intParameter13 - 5, intParameter14 - 10);
g.drawString(intParameter15.toString(), intParameter13 + intParameter15 /2, intParameter14 + intParameter16 + 25);
g.drawString(intParameter16.toString(), intParameter13 + intParameter15 + 5, intParameter14 + intParameter16 /2);
g.drawString(intParameter17.toString(), intParameter13 + 30, intParameter14 + 15);
g.drawString(intParameter18.toString(), intParameter13 + 15, intParameter14 + 30);
break;
}
g.setColor(Color.darkGray);
lengte = (strTekst3.length() * 5)/2;
g.drawString(strTekst3, x - lengte, y);
}
}
public boolean action (Event e, Object o){
if (e.target == teken){
draw = true;
repaint();
return true;
}
if (e.target == vorm){
repaint();
return true;
}
if(e.target == vergrendel1){
if (draw2 == false){
draw2 = true;
intParameter7 = Integer.parseInt(parameter1.getText());
intParameter8 = Integer.parseInt(parameter2.getText());
intParameter9 = Integer.parseInt(parameter3.getText());
intParameter10 = Integer.parseInt(parameter4.getText());
intParameter11 = Integer.parseInt(parameter5.getText());
intParameter12 = Integer.parseInt(parameter6.getText());
strTekst2 = tekst.getText();
intVorm = vorm.getSelectedIndex();
intKleur = kleur.getSelectedIndex();
vergrendel1.setLabel("Ontgrendel 1");
vergrendel1.setBackground(Color.red);
repaint();
} else {
draw2 = false;
vergrendel1.setLabel("Vergrendel 1");
vergrendel1.setBackground(Color.green);
}
return true;
}
if(e.target == vergrendel2){
if(draw3 == false){
draw3 = true;
intParameter13 = Integer.parseInt(parameter1.getText());
intParameter14 = Integer.parseInt(parameter2.getText());
intParameter15 = Integer.parseInt(parameter3.getText());
intParameter16 = Integer.parseInt(parameter4.getText());
intParameter17 = Integer.parseInt(parameter5.getText());
intParameter18 = Integer.parseInt(parameter6.getText());
strTekst3 = tekst.getText();
intVorm2 = vorm.getSelectedIndex();
intKleur2 = kleur.getSelectedIndex();
vergrendel2.setLabel("Ontgrendel 2");
vergrendel2.setBackground(Color.red);
repaint();
} else {
draw3 = false;
vergrendel2.setLabel("Vergrendel 2");
vergrendel2.setBackground(Color.green);
repaint();
}
return true;
}
return false;
}
}
最佳答案
JFrame
而不是 JApplet
。 有一个构造函数并从那里调用 init()
public Kueze(){
init();
}
有一个 main
方法来实例化 Kueze
int
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
new Keuze();
}
});
}
在您的 init()
中,您还需要执行正常的 JFrame
例程
public void init(){
....
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
setVisible(true);
}
参见 JFrame docs看看这些方法做了什么
边注
setSize(...)
。我已经向您展示了如何pack()
paint
方法中有这么多的事情发生?在 paint 方法中,您唯一需要的是实际进行绘画的东西。public void paint
方法下方调用 super.paint(g);
更新
你的代码太长了,我给你布局
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Polygon;
import java.awt.TextField;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Keuze extends JFrame {
....
public Keuze(){
init();
}
public void init(){
....
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
setVisible(true);
}
....
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
new Keuze();
}
});
}
}
关于java - 转换现有的 applet intro 可执行 jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21351495/
我有一个如下图所示的情节。对于这个情节,我想在情节(右下角或左下角)的某处添加类似的线图。我正在使用的子图的命令是 plot( 1:121, sample(1:121),type='l' ) 它绘制在
我有一个单表数据库,我继承并迁移到 SQL Server,然后通过创建、链接和填充一大堆表示主表中项目的查找类型表来规范化它。我现在想用它们的外键替换原始表中的那些项目。我是不是一直在写一堆查询或 U
我有一个 Web 应用程序,它当前正在从服务器获取 PDF 的 base64 表示。我可以使用 Mozilla 的 pdf.js 在 上显示它并使用下拉菜单切换页面。 根据我所能找到的一切和Can
在 DB2 上运行的 Moodle 2 安装中,删除用户不成功,返回从数据库读取错误: Debug info: [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N "
我在grails项目的RH包中添加了一个名为Authorization的新域类。 然后,我从grails菜单自动生成了 Controller 和 View 。 但是当我尝试输入 Controller
今天,我发现了一个有趣的plunker,经过谷歌大量搜索后一无所获,希望我能在这里找到答案。我只是想要那个笨蛋的副本。我不想使用复制和粘贴技术。有什么方法可以获取已建立的 plunk 的副本吗?我如何
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: Migrate normal sqlite3 database to core data? 是否可以将现有的 sql
我正在尝试在我的应用程序上添加启动画面。我干净地构建了程序,但我选择了错误的文件。现在我第二次编辑了 VM 选项并再次干净构建,现在我收到此错误: C:\Users\User\Documents\Ne
我已经查看了很多问题,我不相信这是重复使用单元格的结果,因为新的单元格图像是正确的,但是现有的单元格图像不正确并且曾经是正确的。我会先发布图片,以便更容易理解问题。 我有一个图像单元的 Collect
我在来自 Vaadin 的 ContainerHierarchicalWrapper 的这段代码中有一个非常奇怪的错误: for (Object object : children.keySet())
到目前为止,我正在使用 Globalize用于我的 JavaScript 应用程序的 i18n 和 l10n(使用 jQuery UI 构建)。这行得通,但它将我的代码与另一个特定的库联系在一起。现在
我正在创建一个 JHipster 应用程序,现在确定了 full text search 的必要性.我知道 JHipster 与 Elasticseach 集成,但我在创建项目时没有启用它。有没有一种
我一直在寻找堆栈中的建议,但我仍然不能 100% 确定改进它的最佳方法。我有一个存储大约 130K 条记录的 mysql INNODB“产品”表。杂项产品数据等大约有 80 个字段,然后我们一直在为每
我在一本书上看到,它说:当我们使用另一个初始化新创建的对象时 - 使用复制构造函数创建一个临时对象,然后使用赋值运算符将值复制到新对象! 后来在书中我读到:当使用另一个对象初始化新对象时,编译器创建一
我第一次安装现有的 Django 项目时遇到了启动服务器 python manage.py runserver 的问题 这是我做的 1.克隆仓库, 2.制作虚拟环境 3.pip安装要求.txt 4.生
我有一个网站,还有一个登录表单。我不想使用 PHP 来检查我的 MySQL 数据库,因此我正在寻找一种方法来检查用户凭据以查看是否已有 Linux 用户。我知道 PAM,但我还没有找到任何有关如何从网
我有一个现有的 Umbraco 项目在 IIS 服务器上运行。当我开始这个项目时,我基本上是将 Umbraco 直接安装到服务器上,并通过管理界面进行编码,直到网站启动并上线。 现在,客户想要一些更改
我是 Android 开发新手,目前正在学习一些教程。当我在 Eclipse 中设置一个新的 Android 项目,并选择 Windows -> Android SDK and AVD Manager
我有这个注册页面可以正常工作,但对于电子邮件字段,我需要确保电子邮件正确有效1:正确2 : 有效 为了正确添加电子邮件,我正在使用 Java 脚本验证来维护abc@def.com 很好用 但我的问题是
首先让我说我不熟悉 COM 引用,并且我在 Windows 7 64 位计算机上使用 VS2010。今天早上,我从 TFS 中删除了一个现有项目。然后我尝试构建项目并收到此错误: The type o
我是一名优秀的程序员,十分优秀!