Hirdetés
- Kormányok / autós szimulátorok topikja
- Intel Core i3 / i5 / i7 8xxx "Coffee Lake" és i5 / i7 / i9 9xxx “Coffee Lake Refresh” (LGA1151)
- Milyen videókártyát?
- Azonnali VGA-s kérdések órája
- eGPU tapasztalatok
- Vezetékes FEJhallgatók
- Milyen billentyűzetet vegyek?
- NVIDIA GeForce RTX 5070 / 5070 Ti (GB205 / 203)
- Mi az optikai internet és hogyan működik?
- HDD probléma (nem adatmentés)
Új hozzászólás Aktív témák
-
smallmer
őstag
Sziasztok!
Szeretném kérni a segítségeteket:
Jelenleg így néz ki a kódom:public class testThread implements Runnable, ActionListener {
JFrame frame;
JButton gomb1;
JButton gomb2;
public void makeFrame() {
frame = new JFrame("Frame");
frame.setSize(1000, 500);
frame.getContentPane().setBackground(new Color(74, 74, 74));
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setLayout(null);
}
public void makeButtons() {
gomb1 = new JButton("Indítás");
gomb1.setBounds(350, 300, 100, 30);
gomb1.setBackground(new Color(127, 127, 127));
frame.getContentPane().add(gomb1);
gomb1.addActionListener(this);
gomb2 = new JButton("Stop");
gomb2.setBounds(550, 300, 100, 30);
gomb2.setBackground(new Color(127, 127, 127));
frame.getContentPane().add(gomb2);
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() == gomb1) {
}
}
@Override
public void run() {
try {
go();
} catch (InterruptedException ex) {
Logger.getLogger(server.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void go() throws InterruptedException {
doMore();
}
public void doMore() throws InterruptedException {
for (int i = 0; i < 20; i++) {
System.out.println("Fut a thread" + i);
}
}
}
class Test {
public static void main(String[] args) {
testThread t = new testThread();
t.makeFrame();
t.makeButtons();
Runnable r = new server();
Thread szal = new Thread(r);
Thread szal2 = new Thread(r);
szal.start();
szal2.start();
}
}Azt szeretném megvalósítani, hogy a gomb1-re nyomva elinduljon az egyik szám, majd a gomb2-re nyomva a thread stop() állapotba kerüljön. Tehát egyik gombra kattintva indítsa el a szal-t, majd a másikra nyomva állítsa meg. Hogyan kellene ehhez átalakítani a kódom?
Köszönöm

Új hozzászólás Aktív témák
A topicot kiemeltem. Valaki nem akar egy nyitó hsz-t írni?:))
- One otthoni szolgáltatások (TV, internet, telefon)
- Amazfit T-Rex 3 - prehisztorikus idő
- Battlefield 6
- World of Tanks - MMO
- Megtalálták az akkumulátortechnológiai Szent Grált? - CES
- Kormányok / autós szimulátorok topikja
- Intel Core i3 / i5 / i7 8xxx "Coffee Lake" és i5 / i7 / i9 9xxx “Coffee Lake Refresh” (LGA1151)
- Milyen videókártyát?
- Metal topik
- Ingatlanos topic!
- További aktív témák...
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopszaki Kft.
Város: Budapest



