Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
JPanel answerAddingPanel = new JPanel();
final JPanel answerPanel = new JPanel();
answerAddingPanel.add(answerPanel, "Center");
panel.add(new JScrollPane(answerAddingPanel));
answerAddingPanel.add(addAnswer, "South");
package tutorialsansweradding;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class Main extends JFrame {
public Main(){
final JPanel answerPanel = new JPanel();
answerPanel.setBorder(BorderFactory.createLineBorder(Color.black));
answerPanel.setLayout(new GridLayout(0, 2, 5, 5));
add(new JScrollPane(answerPanel), "Center");
JButton addAnswer = new JButton("Antwort hinzufügen", new ImageIcon("plus.png"));
add(addAnswer, "South");
final Vector<JTextField> Answers = new Vector<JTextField>() ;
addAnswer.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// Ein Label für den Titel
int i = Answers.size()+1;
JLabel label = new JLabel("Antwort "+i);
answerPanel.add(label);
//
JTextField field = new JTextField();
Answers.add(field);
//
answerPanel.add(field);
answerPanel.validate();
answerPanel.setSize(400, i*30);
}
});
setSize(new Dimension(400, 200));
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}