Zum Inhalt springen

wakoz

Mitglieder
  • Gesamte Inhalte

    6
  • Benutzer seit

  • Letzter Besuch

Alle Inhalte von wakoz

  1. Die Positionierung war soweit ok. Geändert an der Positionierung habe ich auch nichts, funzt jetzt aber alles! Mein Fehler war des nicht setzen der Panelgröße und das zuspäte anzeigen des frames mit setVisible. setBounds funzt auch gut, ich nehme aber lieber den anderen weg Generell würde ich lieber einen Manager nutzen, der kann mir aber hier nicht helfen, da ich Leerräume haben werde und die mir Bekannten Layoutmanager würden entweder die Position oder die größe des Panels nicht so setzen wie ich es gern hätte. Die Manager füllen immer die Leerräume des Framein dem sie die Größen und Positionen der inhalte anpassen.
  2. Danke für deine Antwort, Irgendwie blöde von mir Wenn man, so wie ich, mit einem null Layout arbeitet sollte man die Größe des Panels auch entsprechend mit setSize() angeben!
  3. Ich Ändere die Frage!! Wo habe ich den Fehler in der Positionierung des Panels? Bzw. in festsetzen der Größe? Das CenterPanel Soll mittig sitzen und wird leider während der Laufzeit in der Höhe geändert (noch nicht implementiert)
  4. Nabend, Ich Habe mich an einer Kleinen Anwendung versucht, Ich will das MVC Pattern umsetzen habe die Klassen und alles schön sortiert. Nun bin ich mit meiner GUI und der Anwendung fertig so das ich mir die GUI Anzeigen lassen wollte. Also Klasse mit Main geschrieben und Programm Läuft los. Ich nach rechts, gui nach links der Frame wird gezeichnet aber der Panel anscheinend darin nicht. Vielleicht wird auch nur der inhalt nicht gezeichnet, da habe ich aber kein plan :confused: Ich habe repaint und (!oder!) validate getestet, border um das Panel versucht zu legen, aber nie irgendwas im Frame angezeigt bekommen! Hat einer von euch einen Plan, es gibt keine Fehlermeldung! Methoden werden ausgeführt! package view.questionnaire; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.WindowListener; import java.util.Observable; import java.util.Observer; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.border.Border; import javax.swing.border.LineBorder; import model.questionnaire.IObservableModel; import controller.questionnaire.QuestionnaireController; import domain.questionnaire.RichJCheckBox; import domain.questionnaire.event.Actions; import domain.questionnaire.event.LastQuestionEvent; import domain.questionnaire.exerciseContent.Answer; import domain.questionnaire.exerciseContent.Exercise; public class QuestionnaireGUI implements Observer{ private int numberOfQuestions; private int frameCenterY, frameCenterX; private int centerPanelHeight, centerPanelWidth; private int componentHeight = 60; private int componentWidth = 900; private int locationX, locationY; private Dimension minimumSize; private String buttonText = "Weiter"; private JFrame jFrame = null; private JPanel centerPanel = null; private JPanel contentPanel = null; private JPanel bottomPanel = null; private JButton jButton = null; private RichJCheckBox jCheckBox = null; private Font font = new Font("Arial", 1, 20); private JLabel questionLab ,sheetlab; private Exercise exercise = null; private IObservableModel model = null; private QuestionnaireController controller = null; public QuestionnaireGUI(IObservableModel model, QuestionnaireController controller){ this.model = model; this.controller = controller; this.model.addObserver(this); minimumSize = new Dimension(componentWidth, componentHeight); lookAndFeelSetzen(); /*Frame erzeugen*/ jFrame = new JFrame("Quiz"); jFrame.setLayout(null); // Layout des Fensters festgelegen jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);//Fenstergröße Vollbild jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//nur das Aktuelle Fenster schließen jFrame.addWindowListener((WindowListener) this.controller);//Listener fürs Fenster jFrame.setFont(font); /*Frame Mittelpunkt bestimmen*/ frameCenterY = jFrame.getSize().height / 2; frameCenterX = jFrame.getSize().width / 2; /*Panel erzeugen auf dem die Fragen angezeigt werden*/ centerPanel = new JPanel(); centerPanel.setLayout(new FlowLayout()); centerPanel.setMinimumSize(minimumSize); centerPanel.setPreferredSize(minimumSize); centerPanel.setBackground(Color.green); centerPanelWidth = componentWidth + 10;// Breite des Haupt Panels centerPanelHeight = (5 * componentHeight);// Init Höhe (Höhe einer Standart Aufgabe) locationX = frameCenterX - (centerPanelWidth / 2); locationY = frameCenterY - (centerPanelHeight/ 2); //TODO // System.out.println("GUI: 98 " + locationX + " und " + locationY); //TODO centerPanel.setLocation(locationX, locationY); centerPanel.setVisible(true); jFrame.add(centerPanel); /*Fragen Label anzeigen*/ questionLab = new JLabel(); questionLab.setFont(font); jFrame.setVisible(true); } @Override public void update(Observable o, Object arg) { if ( arg instanceof Exercise){ this.exercise = (Exercise) arg; paintExercise(exercise); } else if (arg instanceof Integer){ int argument = ((Integer) arg).intValue(); numberOfQuestions = argument; } else if (arg instanceof LastQuestionEvent){ LastQuestionEvent lastQuestionEvent = (LastQuestionEvent) arg; } } private void paintExercise(Exercise exercise) { // centerPanel.removeAll(); if (bottomPanel == null){ createBottomPanel(); } /*Frage hinzufügen*/ // System.out.println("GUI: Frage " + exercise.getQuestion().getQuestion()); questionLab.setText( exercise.getQuestion().getQuestion() ); contentPanel = new JPanel(); contentPanel.setMinimumSize( minimumSize ); contentPanel.add( questionLab ); contentPanel.setVisible(true); centerPanel.add( contentPanel ); /*Antwortmöglichkeiten hinzufügen*/ int indexID = 0; for (Answer answer : exercise.getAnswers()) { // System.out.println("GUI: Antwortmöglichkeit " +answer.getAnswer()); jCheckBox = new RichJCheckBox(answer.getAnswer(), indexID); jCheckBox.setPreferredSize(minimumSize); jCheckBox.setSelected(false); jCheckBox.setVisible(true); contentPanel = new JPanel(); contentPanel.setMinimumSize( minimumSize ); contentPanel.add( jCheckBox ); contentPanel.setVisible(true); centerPanel.add( contentPanel ); indexID++; } centerPanel.add( bottomPanel ); centerPanel.revalidate(); centerPanel.validate(); // jFrame.setPreferredSize(new Dimension(2 * frameCenterX, 2* frameCenterY)); jFrame.repaint(); // System.out.println("GUI: paintExercise - Paint"); } private void createBottomPanel() { /*Info Panel erzeugen*/ bottomPanel = new JPanel(); bottomPanel.setSize(componentWidth, componentHeight); bottomPanel.setMinimumSize(minimumSize); /*Info Text erzeugen und einfügen*/ sheetlab = new JLabel(); sheetlab.setText(exercise.getQuestionNumber() + " beantwortet von " + numberOfQuestions); bottomPanel.add(sheetlab); /*Weiter Button erzeugen und einfügen*/ jButton = new JButton(); jButton.setText(buttonText); jButton.setActionCommand(Actions.NEXT.toString()); jButton.addActionListener((AbstractAction)controller); bottomPanel.add(jButton); } private void lookAndFeelSetzen() { try { if (System.getProperty("os.name").toString().equals("Mac OS X")) { UIManager.setLookAndFeel("apple.laf.AquaLookAndFeel"); } else { UIManager .setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } } catch (ClassNotFoundException e1) { } catch (InstantiationException e1) { } catch (IllegalAccessException e1) { } catch (UnsupportedLookAndFeelException e1) { } } }
  5. Ich glaub meine Boxen sind kaputt oder gehört das knacken da rein? GoWest ist aber immer noch ein guter titel mit buffer meinst du das byte Array wie würde man dies sinnvoll vergrößern? Muss ja schließlich mit Daten gefüllt werden Danke
  6. äm ich hoffe dir ist bewusst das nur Mono aus zwei boxen ist und das richtiger Stereo Sound daraus besteht das es zwei unterschiedliche Audiospuren gibt:cool: so genug klug ges.... das Thema ist mal interessant :cool: Ich versuche aus einzelnen Double werten eine Ton reihe zu generieren, leider habe ich immer ein knacken zwischen zwei tönen :eek jemand Ahnung woran das liegt? oder wie ich das weg bekomme? package sound.model; import java.util.ArrayList; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; public class SoundGenerator { public SoundGenerator(){ System.out.println("Erzeugt"); } /** * Generates a tone. * * @param herz * Base frequency (neglecting harmonic) of the tone in cycles per * second * @param milliseconds * The number of milliseconds to play the tone. * @param volume * Volume, form 0 (mute) to 100 (max). * @param addHarmonic * Whether to add an harmonic, one octave up. */ public void generateTone(Double herz, int milliseconds, int volume, boolean addHarmonic) throws LineUnavailableException { float frequency = 44100; byte[] buf; AudioFormat af; if (addHarmonic) { buf = new byte[2]; af = new AudioFormat(frequency, 8, 2, true, false); } else { buf = new byte[1]; af = new AudioFormat(frequency, 8, 1, true, false); } SourceDataLine sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); for (int i = 0; i < milliseconds * frequency / 1000; i++) { double angle = i / (frequency / herz) * 2.0 * Math.PI; buf[0] = (byte) (Math.sin(angle) * volume); if (addHarmonic) { double angle2 = (i) / (frequency / herz) * 2.0 * Math.PI; buf[1] = (byte) (Math.sin(2 * angle2) * volume * 0.6); sdl.write(buf, 0, 2); } else { sdl.write(buf, 0, 1); } } sdl.drain(); sdl.stop(); sdl.close(); } /** * Generates a tone. * * @param herz * Base frequency (neglecting harmonic) of the tone in cycles per * second * @param milliseconds * The number of milliseconds to play the tone. * @param volume * Volume, form 0 (mute) to 100 (max). * @param addHarmonic * Whether to add an harmonic, one octave up. */ public void generateTone(ArrayList<Double> soundValues, int milliseconds, int volume, boolean addHarmonic) throws LineUnavailableException { for (Double herz : soundValues) { float frequency = 44100; byte[] buf; AudioFormat af; if (addHarmonic) { buf = new byte[2]; af = new AudioFormat(frequency, 8, 2, true, false); } else { buf = new byte[1]; af = new AudioFormat(frequency, 8, 1, true, false); } SourceDataLine sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); for (int i = 0; i < milliseconds * frequency / 1000; i++) { double angle = i / (frequency / herz) * 2.0 * Math.PI; buf[0] = (byte) (Math.sin(angle) * volume); if (addHarmonic) { double angle2 = (i) / (frequency / herz) * 2.0 * Math.PI; buf[1] = (byte) (Math.sin(2 * angle2) * volume * 0.6); sdl.write(buf, 0, 2); } else { sdl.write(buf, 0, 1); } } sdl.drain(); sdl.stop(); sdl.close(); } } private int milliseconds; private int volume; private boolean addHarmonic; private float frequency = 44100; private byte[] buf; private SourceDataLine sdl; public void setValues( int milliseconds, int volume, boolean addHarmonic){ this.milliseconds = milliseconds; this.volume = volume; this.addHarmonic = addHarmonic; } public void setMilliseconds(int milliseconds){ this.milliseconds = milliseconds; } public void setVolume(int volume){ this.volume = volume; } public void startSound() throws LineUnavailableException{ AudioFormat af; if (addHarmonic) { buf = new byte[2]; af = new AudioFormat(frequency, 8, 2, true, false); } else { buf = new byte[1]; af = new AudioFormat(frequency, 8, 1, true, false); } sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); } public void writeHerz(Double herz){ for (int i = 0; i < milliseconds * frequency / 1000; i++) { double angle = i / (frequency / herz) * 2.0 * Math.PI; buf[0] = (byte) (Math.sin(angle) * volume); if (addHarmonic) { double angle2 = (i) / (frequency / herz) * 2.0 * Math.PI; buf[1] = (byte) (Math.sin(2 * angle2) * volume * 0.6); sdl.write(buf, 0, 2); } else { sdl.write(buf, 0, 1); } } } public void stopSound(){ sdl.drain(); sdl.stop(); sdl.close(); } } Die Tonreihe ist kein Problem aber das Knacken das ich nun so viele Methoden habe liegt daran das ich bereits einiges versucht habe die reihe ohne knacken zu erzeugen, ursprünglich gab es nur die Methode generateTone(Double herz, int milliseconds, int volume, boolean addHarmonic) Ich hoffe das der Thread starter helfen kann

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...